You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Summary:
This PR addresses issue #2371 by reporting inconsistent type args when the same direct base class appears with different type parameters across inheritance paths. It also adds a regression test
Fixes#2371
Pull Request resolved: #2379
Test Plan: python3 test.py
Reviewed By: stroxler
Differential Revision: D92869958
Pulled By: migeed-z
fbshipit-source-id: f282f8b53700cea7db503f9c269bdaeadc806eba
Copy file name to clipboardExpand all lines: conformance/third_party/conformance.exp
+11Lines changed: 11 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -5322,6 +5322,17 @@
5322
5322
"severity": "error",
5323
5323
"stop_column": 29,
5324
5324
"stop_line": 68
5325
+
},
5326
+
{
5327
+
"code": -2,
5328
+
"column": 7,
5329
+
"concise_description": "Class `BadChild` has inconsistent type arguments for base class `Grandparent`: `Grandparent[T1, T2]` and `Grandparent[T2, T1]`",
5330
+
"description": "Class `BadChild` has inconsistent type arguments for base class `Grandparent`: `Grandparent[T1, T2]` and `Grandparent[T2, T1]`",
Copy file name to clipboardExpand all lines: conformance/third_party/conformance.result
+1-3Lines changed: 1 addition & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -94,9 +94,7 @@
94
94
"Line 50: Unexpected errors ['assert_type(str, int | str) failed']",
95
95
"Line 57: Unexpected errors ['assert_type(str, int | str) failed']"
96
96
],
97
-
"generics_base_class.py": [
98
-
"Line 98: Expected 1 errors"
99
-
],
97
+
"generics_base_class.py": [],
100
98
"generics_basic.py": [
101
99
"Line 34: Unexpected errors ['`+` is not supported between `AnyStr` and `AnyStr`\\n Argument `AnyStr` is not assignable to parameter `value` with type `Buffer` in function `bytes.__add__`\\n Protocol `Buffer` requires attribute `__buffer__`', '`+` is not supported between `AnyStr` and `AnyStr`\\n No matching overload found for function `str.__add__` called with arguments: (AnyStr)\\n Possible overloads:\\n (value: LiteralString, /) -> LiteralString\\n (value: str, /) -> str [closest match]']",
Copy file name to clipboardExpand all lines: pyrefly/lib/test/generic_basic.rs
+22-2Lines changed: 22 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -592,7 +592,6 @@ def g(t: type):
592
592
);
593
593
594
594
testcase!(
595
-
bug = "conformance: Should error on inconsistent type variable ordering in base classes",
596
595
test_inconsistent_type_var_ordering_in_bases,
597
596
r#"
598
597
from typing import Generic, TypeVar
@@ -602,7 +601,28 @@ T2 = TypeVar("T2")
602
601
603
602
class Grandparent(Generic[T1, T2]): ...
604
603
class Parent(Grandparent[T1, T2]): ...
605
-
class BadChild(Parent[T1, T2], Grandparent[T2, T1]): ... # should be an error
604
+
class BadChild(Parent[T1, T2], Grandparent[T2, T1]): ... # E: Class `BadChild` has inconsistent type arguments for base class `Grandparent`: `Grandparent[T1, T2]` and `Grandparent[T2, T1]`
605
+
"#,
606
+
);
607
+
608
+
testcase!(
609
+
test_indirect_diamond_inconsistent_targs,
610
+
r#"
611
+
from typing import Generic, TypeVar
612
+
613
+
T = TypeVar("T")
614
+
T1 = TypeVar("T1")
615
+
T2 = TypeVar("T2")
616
+
617
+
class A(Generic[T]): ...
618
+
class B(A[int]): ...
619
+
class C(A[str]): ...
620
+
class D(B, C): ... # E: Class `D` has inconsistent type arguments for base class `A`: `A[int]` and `A[str]`
621
+
622
+
class F(Generic[T1, T2]): ...
623
+
class G(F[int, str]): ...
624
+
class H(F[str, int]): ...
625
+
class I(G, H): ... # E: Class `I` has inconsistent type arguments for base class `F`: `F[int, str]` and `F[str, int]`
0 commit comments