added variance inference test with method scoped type variable#2287
added variance inference test with method scoped type variable#2287randolf-scholz wants to merge 4 commits into
Conversation
|
Actually, let's delay until ty 0.0.36 release (astral-sh/ty#1459) |
|
I understand why you want to clarify this and I'm generally supportive. Would this be considered a spec change? I'm not quite sure if this should be documented and therefore might need a discuss thread. In any case I would like to at least hear the opinions of the Mypy devs here. |
f7047e3 to
d2d1470
Compare
| @@ -1,6 +1,7 @@ | |||
| conformant = "Pass" | |||
There was a problem hiding this comment.
This should be updated to Partial if this is merged.
| def get(self) -> T: | ||
| raise NotImplementedError | ||
|
|
||
| def add[S](self: "ShouldBeCovariant7[S]", other: list[S]) -> "ShouldBeCovariant7[S]": |
There was a problem hiding this comment.
I'm not sure it's correct for this method not to affect variance. (Assuming the class were named C instead for brevity) C[object] has method add taking list[object], where C[int] has method add taking list[int]. That means neither C[object] nor C[int] can safely be substituted for the other, and C should be invariant in T.
So it seems to me that if the algorithm in the spec says this class should be covariant, that might be a bug in the spec text.
Fixes #2281
This adds a conformance test checking that method scoped type-variables do not influence variance inference, in accordance with the spec.