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 not an issue in 0.91, but it occurs in master. Given a metaclass that overrides __or__, the correct type is only maintained in the immediate result. If the result of the __or__ is stored then it will turn to builtins.object.
fromtypingimportUnionclassMyUnion(type): ...
classMeta(type):
def__or__(self, other) ->MyUnion: ... # type: ignoreclassFoo(metaclass=Meta): ...
reveal_type(Foo|Foo) # line 12isinstance(object(), Foo|Foo)
Bar=Foo|Fooreveal_type(Bar) # line 14isinstance(object(), Bar) # line 15
Output in 0.91 (the behavior I expect):
test2.py:12: note: Revealed type is "test2.MyUnion"
test2.py:16: note: Revealed type is "test2.MyUnion"
Output in master:
test2.py:12: note: Revealed type is "test2.MyUnion"
test2.py:16: note: Revealed type is "builtins.object"
test2.py:17: error: Parameterized generics cannot be used with class or instance checks
test2.py:17: error: Argument 2 to "isinstance" has incompatible type "object"; expected "Union[type, UnionType, Tuple[Union[type, UnionType, Tuple[Any, ...]], ...]]"
Edit:
It occurs to me as I re-read PEP 604 that it doesn't specify that OR'd types may create an alias which can be used with isinstance, so maybe my example using it that way is not perfect, but I think the circumstances are still valid.
Edit Edit:
Reading through the PEP 604 discussion thread on typing-sig it seems that aliases composed of unions are to work with isinstance, so even simpler cases are currently broken:
classA: ...
classB: ...
C=A|Breveal_type(C) # Revealed type is "builtins.object"isinstance(object(), C) # error: Parameterized generics cannot be used with class or instance checks# error: Argument 2 to "isinstance" has incompatible type "object"; expected "Union[type, UnionType, Tuple[Union[type, UnionType, Tuple[Any, ...]], ...]]"
Semi-related, this is getting through:
isinstance(object(), int|list[int]) # no error (should be "error: Parameterized generics cannot be used with class or instance checks")
The text was updated successfully, but these errors were encountered:
This is not an issue in 0.91, but it occurs in master. Given a metaclass that overrides
__or__
, the correct type is only maintained in the immediate result. If the result of the__or__
is stored then it will turn tobuiltins.object
.Output in 0.91 (the behavior I expect):
Output in master:
Edit:
It occurs to me as I re-read PEP 604 that it doesn't specify that OR'd types may create an alias which can be used with
isinstance
, so maybe my example using it that way is not perfect, but I think the circumstances are still valid.Edit Edit:
Reading through the PEP 604 discussion thread on typing-sig it seems that aliases composed of unions are to work with
isinstance
, so even simpler cases are currently broken:Semi-related, this is getting through:
The text was updated successfully, but these errors were encountered: