-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Cannot assign an Optional[float]
to a float
#10340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The problem here is that mypy doesn't do type narrowing on
There are some similar existing issues like #7339, but Ivan's comments on that issue suggest that |
If you rephrase your check as |
Ok this works. It does seem unpythonic to disallow truthiness, but whatever works. |
Yeah, definitely a bug / am sort of surprised by this |
No longer happens on master:
|
Thanks, I think this was fixed by #11202 |
Uh oh!
There was an error while loading. Please reload this page.
I have the class below which can optionally take a tuple, which itself optionally has float members, so
(1.0, 2.0)
,None
,(1.0, None)
, etc are all valid inputs.I do checking in the class to see if
None
has been input, and ignore the input in those cases, but mypy is sayingOptional[float]
andfloat
are incompatible for these assignments.How can I specify to mypy that I've done my due diligence in type checking the input?
I'm running mypy 0.812 with Python 3.8.5
The text was updated successfully, but these errors were encountered: