Closed
Description
Hi,
Mypy seems to not be bothered by None
as a default function argument, even if that argument is not an 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
.
Instead, the following code should be considered valid:
from typing import Optional
def type_check_me(index: Optional[int] = None) -> str:
return f"{index}"
Activity
Jiehong commentedon Jul 1, 2020
Note: I tried with
--strict-optional
(even though it's the default now), with no difference.kaste commentedon Jul 1, 2020
I think you're looking for
--no-implicit-optional
https://mypy.readthedocs.io/en/stable/config_file.html#none-and-optional-handlingJelleZijlstra commentedon Jul 1, 2020
Maybe we should flip the default on
--no-implicit-optional
?JukkaL commentedon Jul 3, 2020
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.
JukkaL commentedon Jul 3, 2020
Closing in favor of #9091. Let's continue the discussion there.