With mypy 1.0.0 and mypy-zope 0.9.0, the typechecker seems to think that that isinstance(x, T) is always false when T implements some interface Iand x: Optional[I]. For example, the source
from typing import Optional, reveal_type
from zope.interface import implementer, Interface
class IFoo(Interface):
...
@implementer(IFoo)
class MyFoo:
...
def make_foo() -> Optional[IFoo]:
return MyFoo()
x = make_foo()
reveal_type(x)
assert isinstance(x, MyFoo)
print("hello")
yields
$ mypy temp.py
temp.py:19: note: Revealed type is "Union[temp.IFoo, None]"
temp.py:21: error: Statement is unreachable [unreachable]
Found 1 error in 1 file (checked 1 source file)
but at runtime, we see that the print statement is reachable:
$ python temp.py
Runtime type is 'MyFoo'
hello
Would guess that #90 is related to this somehow.
With mypy 1.0.0 and mypy-zope 0.9.0, the typechecker seems to think that that
isinstance(x, T)is always false whenTimplements some interfaceIandx: Optional[I]. For example, the sourceyields
but at runtime, we see that the print statement is reachable:
Would guess that #90 is related to this somehow.