Open DMRobertson opened 1 year ago
Hm, but isn't it right though? There is no way for mypy to know if x is an instance of MyFoo
. It is an instance of IFoo
according to the description (or maybe None). It may be MyFoo
, or any other implementation of IFoo
.
There is no way for mypy to know if x is an instance of
MyFoo
. It is an instance ofIFoo
according to the description (or maybe None). It may beMyFoo
, or any other implementation ofIFoo
.
I agree with this. But mypy cannot conclude from this that isinstance(x, MyFoo)
must be False in all circumstances---which is what I think leads to the unreachable
error.
That's fair. I'll take to look.
Many thanks! FWIW we've only seen this problem when checking our test, so it's not the end of the world as is!
It is strange, but I can't repro it - see #92. @DMRobertson are you using some special mypy configuration to trigger the problem?
Ahh, sorry. I should have double-checked this with a clean environment.
I think you need the --warn-unreachable
command line flag to see this behaviour. (I was using Synapse's mypy config which has this turned on by default.)
With mypy 1.0.0 and mypy-zope 0.9.0, the typechecker seems to think that that
isinstance(x, T)
is always false whenT
implements some interfaceI
andx: 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.