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
{{ message }}
Repository navigation
Incompatible types: Union[bool, A] and Optional[A] #11043
Mypy doesn't currently narrow bool types when the value is compared against True or False, so the type of x within the else clause is Union[bool, Foo]. This new capability would need to be added to make the above code type check without error.
For now, you could work around it using the technique you identified, or you can add a assert not isinstance(x, bool) statement in the else clause of the errors method.
Activity
erictraut commentedon Sep 2, 2021
Mypy doesn't currently narrow
booltypes when the value is compared againstTrueorFalse, so the type ofxwithin the else clause isUnion[bool, Foo]. This new capability would need to be added to make the above code type check without error.For now, you could work around it using the technique you identified, or you can add a
assert not isinstance(x, bool)statement in theelseclause of theerrorsmethod.hauntsaninja commentedon Oct 31, 2021
Thanks, this will be fixed by #10389