Skip to content

Commit 2b60460

Browse files
committed
New test cases for generics_base_class.
1 parent e0aa9d9 commit 2b60460

File tree

8 files changed

+60
-9
lines changed

8 files changed

+60
-9
lines changed

conformance/results/mypy/generics_base_class.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
conformant = "Pass"
1+
conformant = "Partial"
2+
notes = """
3+
Does not detect inconsistent type variable ordering.
4+
"""
25
output = """
36
generics_base_class.py:26: error: Argument 1 to "takes_dict_incorrect" has incompatible type "SymbolTable"; expected "dict[str, list[object]]" [arg-type]
47
generics_base_class.py:29: error: Variable "typing.Generic" is not valid as a type [valid-type]
@@ -9,6 +12,7 @@ generics_base_class.py:49: error: "LinkedList" expects 1 type argument, but 2 gi
912
generics_base_class.py:61: error: "MyDict" expects 1 type argument, but 2 given [type-arg]
1013
generics_base_class.py:68: error: Duplicate type variables in Generic[...] or Protocol[...] [misc]
1114
"""
12-
conformance_automated = "Pass"
15+
conformance_automated = "Fail"
1316
errors_diff = """
17+
Line 98: Expected 1 errors
1418
"""
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
version = "mypy 1.13.0"
2-
test_duration = 2.6
2+
test_duration = 2.5

conformance/results/pyre/generics_base_class.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ conformant = "Partial"
22
notes = """
33
Does not reject illegal use of Generic.
44
Does not allow using generic in assert_type expression.
5+
Does not detect inconsistent type variable ordering.
56
"""
67
output = """
78
generics_base_class.py:26:25 Incompatible parameter type [6]: In call `takes_dict_incorrect`, for 1st positional argument, expected `Dict[str, List[object]]` but got `SymbolTable`.
@@ -13,4 +14,5 @@ conformance_automated = "Fail"
1314
errors_diff = """
1415
Line 29: Expected 1 errors
1516
Line 30: Expected 1 errors
17+
Line 98: Expected 1 errors
1618
"""
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
version = "pyre 0.9.23"
2-
test_duration = 4.3
2+
test_duration = 4.4

conformance/results/pyright/generics_base_class.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ generics_base_class.py:30:8 - error: "Generic" is not valid in this context (rep
1010
generics_base_class.py:49:38 - error: Too many type arguments provided for "LinkedList"; expected 1 but received 2 (reportInvalidTypeArguments)
1111
generics_base_class.py:61:30 - error: Too many type arguments provided for "MyDict"; expected 1 but received 2 (reportInvalidTypeArguments)
1212
generics_base_class.py:68:28 - error: Type arguments for "Generic" must be unique (reportInvalidTypeForm)
13+
generics_base_class.py:98:7 - error: Base classes of BadChild are mutually incompatible
14+
  Base class "Grandparent[T2@BadChild, T1@BadChild]" derives from "Grandparent[T2@BadChild, T1@BadChild]" which is incompatible with type "Grandparent[T1@BadChild, T2@BadChild]" (reportGeneralTypeIssues)
1315
"""
1416
conformance_automated = "Pass"
1517
errors_diff = """

conformance/results/pytype/generics_base_class.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ conformant = "Partial"
22
notes = """
33
False negative on passing SymbolTable to dict[str, list[object]].
44
Does not reject illegal use of Generic.
5+
Wrong type variable order when inheriting from multiple generic base classes.
56
"""
67
output = """
78
generics_base_class.py:29:1: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in <module>: Invalid type annotation 'T' [invalid-annotation]
@@ -26,9 +27,26 @@ generics_base_class.py:68:17: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in <m
2627
class BadClass1(Generic[T, T]): # E
2728
\u001b[1m\u001b[31m~~~~~~~~~~~~~\u001b[39m\u001b[0m
2829
30+
generics_base_class.py:90:1: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in <module>: Function takes_parent1 was called with the wrong arguments [wrong-arg-types]
31+
32+
takes_parent1(child) # OK
33+
\u001b[1m\u001b[31m~~~~~~~~~~~~~~~~~~~~\u001b[39m\u001b[0m
34+
35+
generics_base_class.py:91:1: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in <module>: Function takes_parent2 was called with the wrong arguments [wrong-arg-types]
36+
37+
takes_parent2(child) # OK
38+
\u001b[1m\u001b[31m~~~~~~~~~~~~~~~~~~~~\u001b[39m\u001b[0m
39+
40+
generics_base_class.py:98:1: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in <module>: Invalid type annotation 'BadChild' [invalid-annotation]
41+
42+
class BadChild(Parent[T1, T2], Grandparent[T2, T1]): ... # E
43+
\u001b[1m\u001b[31m~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\u001b[39m\u001b[0m
44+
2945
"""
3046
conformance_automated = "Fail"
3147
errors_diff = """
3248
Line 26: Expected 1 errors
3349
Line 30: Expected 1 errors
50+
Line 90: Unexpected errors ['generics_base_class.py:90:1: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in <module>: Function takes_parent1 was called with the wrong arguments [wrong-arg-types]']
51+
Line 91: Unexpected errors ['generics_base_class.py:91:1: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in <module>: Function takes_parent2 was called with the wrong arguments [wrong-arg-types]']
3452
"""

conformance/results/results.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,13 @@ <h3>Python Type System Conformance Test Results</h3>
159159
<div class="table_container"><table><tbody>
160160
<tr><th class="col1">&nbsp;</th>
161161
<th class='tc-header'><div class='tc-name'>mypy 1.13.0</div>
162-
<div class='tc-time'>2.6sec</div>
162+
<div class='tc-time'>2.5sec</div>
163163
</th>
164164
<th class='tc-header'><div class='tc-name'>pyright 1.1.389</div>
165165
<div class='tc-time'>2.6sec</div>
166166
</th>
167167
<th class='tc-header'><div class='tc-name'>pyre 0.9.23</div>
168-
<div class='tc-time'>4.3sec</div>
168+
<div class='tc-time'>4.4sec</div>
169169
</th>
170170
<th class='tc-header'><div class='tc-name'>pytype 2024.10.11</div>
171171
<div class='tc-time'>45.1sec</div>
@@ -241,10 +241,10 @@ <h3>Python Type System Conformance Test Results</h3>
241241
<a class="test_group" href="https://typing.readthedocs.io/en/latest/spec/generics.html">Generics</a>
242242
</th></tr>
243243
<tr><th class="column col1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;generics_base_class</th>
244+
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Does not detect inconsistent type variable ordering.</p></span></div></th>
244245
<th class="column col2 conformant">Pass</th>
245-
<th class="column col2 conformant">Pass</th>
246-
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Does not reject illegal use of Generic.</p><p>Does not allow using generic in assert_type expression.</p></span></div></th>
247-
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>False negative on passing SymbolTable to dict[str, list[object]].</p><p>Does not reject illegal use of Generic.</p></span></div></th>
246+
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Does not reject illegal use of Generic.</p><p>Does not allow using generic in assert_type expression.</p><p>Does not detect inconsistent type variable ordering.</p></span></div></th>
247+
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>False negative on passing SymbolTable to dict[str, list[object]].</p><p>Does not reject illegal use of Generic.</p><p>Wrong type variable order when inheriting from multiple generic base classes.</p></span></div></th>
248248
</tr>
249249
<tr><th class="column col1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;generics_basic</th>
250250
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Does not reject the use of a constraint parameterized by another type variable.</p></span></div></th>

conformance/tests/generics_base_class.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,28 @@ class BadClass1(Generic[T, T]): # E
7171

7272
class GoodClass1(dict[T, T]): # OK
7373
pass
74+
75+
# > Type variables are applied to the defined class in the order in which
76+
# > they first appear in any generic base classes.
77+
78+
T1 = TypeVar("T1")
79+
T2 = TypeVar("T2")
80+
T3 = TypeVar("T3")
81+
82+
class Parent1(Generic[T1, T2]): ...
83+
class Parent2(Generic[T1, T2]): ...
84+
class Child(Parent1[T1, T3], Parent2[T2, T3]): ...
85+
86+
def takes_parent1(x: Parent1[int, bytes]): ...
87+
def takes_parent2(x: Parent2[str, bytes]): ...
88+
89+
child: Child[int, bytes, str] = Child()
90+
takes_parent1(child) # OK
91+
takes_parent2(child) # OK
92+
93+
# > A type checker should report an error when the type variable order is
94+
# > inconsistent.
95+
96+
class Grandparent(Generic[T1, T2]): ...
97+
class Parent(Grandparent[T1, T2]): ...
98+
class BadChild(Parent[T1, T2], Grandparent[T2, T1]): ... # E

0 commit comments

Comments
 (0)