You signed in with anot
8000
her 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
from typing import Type
class Meta(type):
pass
class Thing(metaclass=Meta):
pass
def foo(x: Type[Thing]) -> Type[Thing]:
assert isinstance(x, Meta)
return x
with the error Incompatible return value type (got "Meta", expected "Type[Thing]").
Previously this worked because we thought that Meta and Type[Thing] had no overlap and so the rest of the function after the assert wasn't checked.
This caused one error in S.
The answer might be that we need to consider Type[Thing] to be a subtype of Meta?
The text was updated successfully, but these errors were encountered:
The answer might be that we need to consider Type[Thing] to be a subtype of Meta?
IIRC this is already true, we need to fix proper subtype (which is still a separate visitor, see also #3297)
Also even with proper subtype fixed, this may not help since isinstance() can widen type, see #6386. Or maybe better proper subtype check will fix both issues.
Fixes#4616Fixes#6416Fixes#6386
Currently `Type[C]` is considered a subtype of metaclass of `C`, and I think this is right. The idea is to fix `ProperSubtypeVisitor.visit_type_type()` to match `SubtypeVisitor.visit_type_type()` (plus couple small updates to make the former used by `isinstance()` and `issubclass()`).
Since #6370, we reject the following code:
with the error
Incompatible return value type (got "Meta", expected "Type[Thing]")
.Previously this worked because we thought that
Meta
andType[Thing]
had no overlap and so the rest of the function after the assert wasn't checked.This caused one error in S.
The answer might be that we need to consider
Type[Thing]
to be a subtype ofMeta
?The text was updated successfully, but these errors were encountered: