We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Hi,
Mypy seems to not be bothered by None as a default function argument, even if that argument is not an Optional.
None
Optional
Here is an example:
def type_check_me(index: int = None) -> str: return f"{index}"
Running mypy on this does not lead to any issue.
mypy version: 0.782
Expected:
I would expect mypy to tell me that None is not a valid default value for index, because it has type int.
index
int
Instead, the following code should be considered valid:
from typing import Optional def type_check_me(index: Optional[int] = None) -> str: return f"{index}"
The text was updated successfully, but these errors were encountered:
Note: I tried with --strict-optional (even though it's the default now), with no difference.
--strict-optional
Sorry, something went wrong.
I think you're looking for --no-implicit-optional https://mypy.readthedocs.io/en/stable/config_file.html#none-and-optional-handling
--no-implicit-optional
Maybe we should flip the default on --no-implicit-optional?
Yeah, I've been thinking about this. We might want to do it separately from other major breaking changes, such as the switch to a modular typeshed.
Closing in favor of #9091. Let's continue the discussion there.
No branches or pull requests
Hi,
Mypy seems to not be bothered by
None
as a default function argument, even if that argument is not anOptional
.Here is an example:
Running mypy on this does not lead to any issue.
mypy version: 0.782
Expected:
I would expect mypy to tell me that
None
is not a valid default value forindex
, because it has typeint
.Instead, the following code should be considered valid:
The text was updated successfully, but these errors were encountered: