mirror of
https://github.com/microsoft/pyright.git
synced 2024-09-11 07:55:56 +03:00
Fixed bug that resulted in a false positive error relating to variance incompatibility. This addresses https://github.com/microsoft/pyright/issues/4111.
This commit is contained in:
parent
e2e3a5c9ff
commit
425908eced
@ -7175,7 +7175,8 @@ export function createTypeEvaluator(importLookup: ImportLookup, evaluatorOptions
|
||||
EvaluatorFlags.DoNotSpecialize |
|
||||
EvaluatorFlags.DisallowParamSpec |
|
||||
EvaluatorFlags.DisallowTypeVarTuple |
|
||||
EvaluatorFlags.AllowRequired
|
||||
EvaluatorFlags.AllowRequired |
|
||||
EvaluatorFlags.EnforceTypeVarVarianceConsistency
|
||||
);
|
||||
|
||||
if (!options?.isAnnotatedClass) {
|
||||
|
@ -676,8 +676,8 @@
|
||||
"useListInstead": "Use List[T] to indicate a list type or Union[T1, T2] to indicate a union type",
|
||||
"useTupleInstead": "Use Tuple[T1, ..., Tn] to indicate a tuple type or Union[T1, T2] to indicate a union type",
|
||||
"useTypeInstead": "Use Type[T] instead",
|
||||
"varianceMismatchForClass": "Variance of TypeVar \"{typeVarName}\" is incompatible with base class \"{className}\"",
|
||||
"varianceMismatchForTypeAlias": "Variance of TypeVar \"{typeVarName}\" is incompatible with \"{typeAliasParam}\""
|
||||
"varianceMismatchForClass": "Variance of type argument \"{typeVarName}\" is incompatible with base class \"{className}\"",
|
||||
"varianceMismatchForTypeAlias": "Variance of type argument \"{typeVarName}\" is incompatible with \"{typeAliasParam}\""
|
||||
},
|
||||
"CodeAction": {
|
||||
"addOptionalToAnnotation": "Add \"Optional\" to Type Annotation",
|
||||
|
@ -60,8 +60,6 @@ class Class5(Generic[T_contra]):
|
||||
...
|
||||
|
||||
|
||||
# This should generate an error because frozenset
|
||||
# takes a covariant type parameter.
|
||||
class Class5_Child1(Class5[frozenset[T_contra]]):
|
||||
...
|
||||
|
||||
@ -105,3 +103,31 @@ class Class6_Child4(Class6[T, T]):
|
||||
# compatible with T_contra.
|
||||
class Class6_Child5(Class6[Sequence[T_co], Sequence[T_co]]):
|
||||
...
|
||||
|
||||
|
||||
class Co(Generic[T_co]):
|
||||
...
|
||||
|
||||
|
||||
class Contra(Generic[T_contra]):
|
||||
...
|
||||
|
||||
|
||||
class CoToContra(Generic[T_contra]):
|
||||
def f(self, arg: Co[T_contra]) -> None:
|
||||
...
|
||||
|
||||
|
||||
class ContraToContra(Generic[T_co]):
|
||||
def f(self, arg: Contra[T_co]) -> None:
|
||||
...
|
||||
|
||||
|
||||
class CoToCo(Generic[T_co]):
|
||||
def f(self) -> Co[T_co]:
|
||||
...
|
||||
|
||||
|
||||
class ContraToCo(Generic[T_contra]):
|
||||
def f(self) -> Contra[T_contra]:
|
||||
...
|
||||
|
@ -33,13 +33,13 @@ class A_3(A[T2]):
|
||||
...
|
||||
|
||||
|
||||
A_Alias_3 = A[T2] | Callable[[T3], T2]
|
||||
class B(Generic[T1, T2]):
|
||||
pass
|
||||
|
||||
|
||||
class B(list[A_Alias_3[T1, T2]]):
|
||||
...
|
||||
B_Alias_1 = B[T2, T3]
|
||||
|
||||
|
||||
# This should generate an error because the variance is incompatible.
|
||||
class C(list[A_Alias_3[T3, T3]]):
|
||||
class C(B_Alias_1[T3, T2]):
|
||||
...
|
||||
|
@ -981,7 +981,7 @@ test('GenericTypes96', () => {
|
||||
test('GenericTypes97', () => {
|
||||
const analysisResults = TestUtils.typeAnalyzeSampleFiles(['genericTypes97.py']);
|
||||
|
||||
TestUtils.validateResults(analysisResults, 9);
|
||||
TestUtils.validateResults(analysisResults, 8);
|
||||
});
|
||||
|
||||
test('GenericTypes98', () => {
|
||||
|
Loading…
Reference in New Issue
Block a user