Union of legit types is also a legit type #1796
-
Is there anyway in Python's typing system to have something like this work: class OriginalType: ...
class SubclassOne(OriginalType): ...
class SubclassTwo(OriginalType): ...
UnionType = SubclassOne | SubclassTwo
def some_function(_: type[OriginalType]): ...
some_function(UnionType) I want to be able to limit the argument of my function to a specific union of arbitrary subclasses of the base class. A real life usage of such function is here: https://github.com/sassanh/python-redux/blob/main/tests/test_features.py#L127 Context: microsoft/pyright#8390 Is it not possible until https://peps.python.org/pep-0747/ is done? |
Beta Was this translation helpful? Give feedback.
Answered by
JelleZijlstra
Jul 12, 2024
Replies: 1 comment
-
Yes, this is a use case for PEP-747. A union is not an instance of |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
sassanh
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes, this is a use case for PEP-747. A union is not an instance of
type
, so it is not assignable totype[]
.