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
This is a low-priority issue (or maybe should even be closed), just wanted to add it for the record in case others run into it.
When --strict-optional is turned off, mypy in some cases is unable to infer the correct type inside ... if None else ... type conditionals; this doesn't happen always, only if it's preceded with assert isinstance(x, (X, type(None))) when x was known to be of type Base, which is the base class of X:
from typing import *
class A:
a = 1
class B(A):
b = 2
def f(x: Union[A, None]) -> None:
assert isinstance(x, (B, type(None)))
y = x.b if x is not None else x # fails type check if --strict-optional is off, passes otherwise
The fix would be messy (mypy correctly analyzes the if statement, the problem is that it ignores the isinstance because it thinks that the assertion always succeeds anyway due to some problem with None handling).
The text was updated successfully, but these errors were encountered:
I can't reproduce the error on 0.620+ (I've tried installing earlier versions locally, but wasn't easily able to).
--strict-optional has been the default for a while now, and I think the people enabling the old behaviour with --no-strict-optional are becoming rarer and rarer.
There's been no activity on the issue since its creation five years ago.
The issue was low-priority when it was first created five years ago, and is even lower priority now.
This is a low-priority issue (or maybe should even be closed), just wanted to add it for the record in case others run into it.
When
--strict-optional
is turned off, mypy in some cases is unable to infer the correct type inside... if None else ...
type conditionals; this doesn't happen always, only if it's preceded withassert isinstance(x, (X, type(None)))
whenx
was known to be of typeBase
, which is the base class ofX
:The fix would be messy (mypy correctly analyzes the
if
statement, the problem is that it ignores theisinstance
because it thinks that the assertion always succeeds anyway due to some problem withNone
handling).The text was updated successfully, but these errors were encountered: