How to create TypeVar
that is either a subclass of A
or a subclass of B
?
#1260
Unanswered
randolf-scholz
asked this question in
Q&A
Replies: 1 comment 8 replies
-
A bound TypeVar won't work in this case if you expect A constrained TypeVar should work in this case. Mypy appears to have a bug here on the line that begins with |
Beta Was this translation helpful? Give feedback.
8 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Consider the case when we want a
TypeVar
namedX
that is either a subclass ofA
, or a subclass ofB
.Neither
X=TypeVar("X", bound=Union[A,B])
norX = TypeVar("X", A, B, covariant=True)
seem to do the right thing (see example below).Minimal Working Example
using
python=3.10.6
andmypy=0.971
.Beta Was this translation helpful? Give feedback.
All reactions