-
-
Notifications
You must be signed in to change notification settings - Fork 3k
[1.16 makes more common] Inference of Any against optional type infers Never #8829
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
Definitely a bug and a somewhat surprising one too. Probably an issue in constraints.py? |
The root cause is: a: Any
def assert_not_none(value: Optional[T]) -> T: ...
reveal_type(assert_not_none(a)) # Revealed type is "Never" (and same with |
I encountered this when preparing an internal codebase for the 1.16 release. The issue wasn't directly related to any change in 1.16, though -- some additional |
Fixes #8829 This case is more common in 1.16 due to some changes in binder, so it would be good to fix it. My fix may be a bit naive, but if `mypy_primer` looks good, I think it should be OK.
See the following example:
I would expect that
foo1
andfoo2
are equivalent. However, runningmypy
on this file, I get:test.py:12: error: Value of type <nothing> is not indexable
For some reason,
assert_not_none
doesn't mapOptional[Any]
toAny
, as it is supposed to (and which would accept the indexing), but instead maps it to<nothing>
which throws an error. The second version with asserting that it is not None seems to work fine, though.The text was updated successfully, but these errors were encountered: