Does replacing a type variable make a subclass incompatible? #11605
Labels
bug
mypy got something wrong
topic-inheritance
Inheritance and incompatible overrides
topic-type-variables
Bug Report
Replace a type variable with another one (by specializing and then another generic). Is this type safe?
To Reproduce
Here's some pretty minimal code:
Expected Behavior
I'm not sure, honestly. My gut instinct is that mypy is right here and LSP is being violated... but I can't think of any sequence of functions to run to get type unsafety without resorting to
typing.Any
which brings its own unsafety. Additionally, pyright does not mark this as an error (though that just may be me failing to use pyright correctly...).Actual Behavior
Your Environment
mypy.ini
(and other config files): none (mypy-playground)in simpler (?) terms
I have
Thing<A: upper bound 1>
, specialize it to beSpecializedThing
, then generic something in it to getCoolSpecializedThing<B: upper bound 2>
. Is that OK, doesCoolSpecializedThing
work?But confounding the question more, I have a
something<T: Thing<A>>(self: T) -> T
and I reimplement that onCoolSpecializedThing
to getsomething<T: CoolSpecializedThing<B>>(self: T) -> T
.Normally with subclassing, this is fine:
And since
CoolSpecializedThing
is a subclass ofThing
this should work right??And yet the type variables have different upper bounds so like..... arghhhh. (I can't replace
Thing<whatever>
withCoolSpecializedThing<whatever>
as the upper bounds of the type variables are different)(I'll be honest, I'm mainly opening this issue here because I'm curious about this, I'm certain I can work around this one way or another).
The text was updated successfully, but these errors were encountered: