You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The original PEP 484 indicated that when a parameter had a None default argument, it should be interpreted implicitly as though the declared type were unioned with None. The PEP was later revised, but it looks like mypy still defaults to this old behavior. If you use --strict mode, mypy does report this error.
--no-implicit-optional would explicitly enable this behavior (--strict has "other" side-effects too).
I'm personally more in favor of the implicit behavior (mypy default) - but struggled to find the "proper" flag for it while opening the issue.
I've now also discovered pyrights strictParameterNoneValue - which allows to align the behavior of the 2 tools (although they have diverging defaults).
Bug Report
Type-checking a method with a typed argument (typed to any regular type) with
None
as default yields no error.I would expect this to be a type-error - as the real type of
other
in the below case isOptional[str]
.To Reproduce
Playground:
https://mypy-play.net/?mypy=master&python=3.10&gist=c9a5da3dab27e76281498b25ca3a5e4d
Expected Behavior
Raising problematic default value, causing either a change in default, or a re-typing to
Optional[str]
.Actual Behavior
No error from mypy
Interestingly, pyright does properly detect this and raises the following error (this is how i discovered this bug).
Your Environment
mypy.ini
(and other config files): /The text was updated successfully, but these errors were encountered: