mirror of
https://github.com/microsoft/pyright.git
synced 2024-09-17 11:17:17 +03:00
Fixed bug that resulted in the incorrect variance inference of an "auto variance" type parameter (as introduced in PEP 695).
This commit is contained in:
parent
5569939ee6
commit
ed295ddcaf
@ -2520,6 +2520,12 @@ export namespace TypeVarType {
|
||||
// By this point, the variance should have been inferred.
|
||||
assert(variance !== Variance.Auto, 'Expected variance to be inferred');
|
||||
|
||||
// If we're in the process of computing variance, it will still be
|
||||
// unknown. Default to covariant in this case.
|
||||
if (variance === Variance.Unknown) {
|
||||
return Variance.Covariant;
|
||||
}
|
||||
|
||||
return variance;
|
||||
}
|
||||
|
||||
|
@ -24,6 +24,13 @@ vco2_1: ShouldBeCovariant2[float] = ShouldBeCovariant2[int]()
|
||||
vco2_2: ShouldBeCovariant2[int] = ShouldBeCovariant2[float]()
|
||||
|
||||
|
||||
class ShouldBeCovariant3[T]:
|
||||
def method1(self) -> "ShouldBeCovariant2[T]":
|
||||
...
|
||||
|
||||
|
||||
vco3_1: ShouldBeCovariant3[float] = ShouldBeCovariant3[int]()
|
||||
|
||||
|
||||
class ShouldBeInvariant1[T]:
|
||||
def __init__(self, value: T) -> None:
|
||||
|
Loading…
Reference in New Issue
Block a user