Skip to content

Commit a65f949

Browse files
committed
New test cases in generics_basic.
1 parent 2b60460 commit a65f949

File tree

9 files changed

+76
-18
lines changed

9 files changed

+76
-18
lines changed

conformance/results/mypy/generics_basic.toml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@ generics_basic.py:69: error: Value of type variable "AnyStr" of "concat" cannot
1010
generics_basic.py:121: error: Duplicate type variables in Generic[...] or Protocol[...] [misc]
1111
generics_basic.py:157: error: Invalid index type "int" for "MyMap1[str, int]"; expected type "str" [index]
1212
generics_basic.py:158: error: Invalid index type "int" for "MyMap2[int, str]"; expected type "str" [index]
13-
generics_basic.py:191: error: Dynamic metaclass not supported for "GenericMetaInstance" [misc]
14-
generics_basic.py:191: error: Type variable "generics_basic.T" is unbound [valid-type]
15-
generics_basic.py:191: note: (Hint: Use "Generic[T]" or "Protocol[T]" base class to bind "T" inside a class)
16-
generics_basic.py:191: note: (Hint: Use "T" in function signature to bind "T" inside a function)
13+
generics_basic.py:162: error: Free type variable expected in Generic[...] [misc]
14+
generics_basic.py:163: error: Free type variable expected in Protocol[...] [misc]
15+
generics_basic.py:171: error: If Generic[...] or Protocol[...] is present it should list all type variables [misc]
16+
generics_basic.py:172: error: If Generic[...] or Protocol[...] is present it should list all type variables [misc]
17+
generics_basic.py:208: error: Dynamic metaclass not supported for "GenericMetaInstance" [misc]
18+
generics_basic.py:208: error: Type variable "generics_basic.T" is unbound [valid-type]
19+
generics_basic.py:208: note: (Hint: Use "Generic[T]" or "Protocol[T]" base class to bind "T" inside a class)
20+
generics_basic.py:208: note: (Hint: Use "T" in function signature to bind "T" inside a function)
1721
"""
1822
conformance_automated = "Fail"
1923
errors_diff = """

conformance/results/pyre/generics_basic.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ False positives in examples using constrained type variables.
44
False negative for constraint parameterized by a type variable.
55
False negative in custom map example.
66
False positive using `iter`.
7+
False negative for bad type arguments to Generic/Protocol.
78
False negative for generic metaclass.
89
"""
910
output = """
@@ -16,10 +17,14 @@ generics_basic.py:69:14 Incompatible parameter type [6]: In call `concat`, for 2
1617
generics_basic.py:121:0 Duplicate type variables [59]: Duplicate type variable `T` in Generic[...].
1718
generics_basic.py:157:7 Incompatible parameter type [6]: In call `typing.Mapping.__getitem__`, for 1st positional argument, expected `str` but got `int`.
1819
generics_basic.py:158:7 Incompatible parameter type [6]: In call `typing.Mapping.__getitem__`, for 1st positional argument, expected `str` but got `int`.
20+
generics_basic.py:171:11 Invalid type variable [34]: The current class isn't generic with respect to the type variable `Variable[T_co]`. To reference the type variable, you can modify the class to inherit from `typing.Generic[T_co]`.
21+
generics_basic.py:172:11 Invalid type variable [34]: The current class isn't generic with respect to the type variable `Variable[T_co]`. To reference the type variable, you can modify the class to inherit from `typing.Generic[T_co]`.
1922
"""
2023
conformance_automated = "Fail"
2124
errors_diff = """
2225
Line 55: Expected 1 errors
23-
Line 191: Expected 1 errors
26+
Line 162: Expected 1 errors
27+
Line 163: Expected 1 errors
28+
Line 208: Expected 1 errors
2429
Line 34: Unexpected errors ['generics_basic.py:34:4 Incompatible return type [7]: Expected `Variable[AnyStr <: [str, bytes]]` but got `str`.', 'generics_basic.py:34:15 Incompatible parameter type [6]: In call `str.__add__`, for 1st positional argument, expected `str` but got `Variable[AnyStr <: [str, bytes]]`.']
2530
"""

conformance/results/pyre/version.toml

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.4
2+
test_duration = 4.3

conformance/results/pyright/generics_basic.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@ generics_basic.py:157:5 - error: Argument of type "Literal[0]" cannot be assigne
1313
  "Literal[0]" is not assignable to "str" (reportArgumentType)
1414
generics_basic.py:158:5 - error: Argument of type "Literal[0]" cannot be assigned to parameter "key" of type "str" in function "__getitem__"
1515
  "Literal[0]" is not assignable to "str" (reportArgumentType)
16-
generics_basic.py:191:37 - error: Metaclass cannot be generic (reportGeneralTypeIssues)
16+
generics_basic.py:162:20 - error: Type argument for "Generic" must be a type variable (reportInvalidTypeForm)
17+
generics_basic.py:163:21 - error: Type argument for "Protocol" must be a type parameter (reportInvalidTypeForm)
18+
generics_basic.py:171:7 - error: Generic[] or Protocol[] must include all type variables
19+
  Missing type variables: "T_co" (reportGeneralTypeIssues)
20+
generics_basic.py:172:7 - error: Generic[] or Protocol[] must include all type variables
21+
  Missing type variables: "T_co" (reportGeneralTypeIssues)
22+
generics_basic.py:208:37 - error: Metaclass cannot be generic (reportGeneralTypeIssues)
1723
"""
1824
conformance_automated = "Pass"
1925
errors_diff = """
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
version = "pyright 1.1.389"
2-
test_duration = 2.6
2+
test_duration = 2.5

conformance/results/pytype/generics_basic.toml

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
conformant = "Partial"
22
notes = """
33
False positives in examples using constrained type variables.
4+
Argument 'covariant' to TypeVar not supported.
5+
False negative for type variables missing from Generic/Protocol base class.
46
False negative for generic metaclass.
57
"""
68
output = """
@@ -66,17 +68,41 @@ generics_basic.py:158:5: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in test_my
6668
m2[0] # E
6769
\u001b[1m\u001b[31m~~~~~\u001b[39m\u001b[0m
6870
69-
generics_basic.py:182:5: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in test_my_iterable_any: Iterator[nothing] [assert-type]
71+
generics_basic.py:162:12: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in <module>: Invalid type annotation 'Generic' [invalid-annotation]
72+
73+
class Bad1(Generic[int]): ... # E
74+
\u001b[1m\u001b[31m~~~~~~~~~~~~\u001b[39m\u001b[0m
75+
76+
generics_basic.py:163:12: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in <module>: Invalid type annotation 'Protocol' [invalid-annotation]
77+
78+
class Bad2(Protocol[int]): ... # E
79+
\u001b[1m\u001b[31m~~~~~~~~~~~~~\u001b[39m\u001b[0m
80+
81+
generics_basic.py:168:8: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in <module>: argument "covariant" to TypeVar not supported yet [not-supported-yet]
82+
83+
T_co = TypeVar("T_co", covariant=True)
84+
\u001b[1m\u001b[31m~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\u001b[39m\u001b[0m
85+
86+
generics_basic.py:169:8: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in <module>: argument "covariant" to TypeVar not supported yet [not-supported-yet]
87+
88+
S_co = TypeVar("S_co", covariant=True)
89+
\u001b[1m\u001b[31m~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\u001b[39m\u001b[0m
90+
91+
generics_basic.py:199:5: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in test_my_iterable_any: Iterator[nothing] [assert-type]
7092
7193
assert_type(iter(m), Iterator[Any])
7294
\u001b[1m\u001b[31m~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\u001b[39m\u001b[0m
7395
7496
"""
7597
conformance_automated = "Fail"
7698
errors_diff = """
77-
Line 191: Expected 1 errors
99+
Line 171: Expected 1 errors
100+
Line 172: Expected 1 errors
101+
Line 208: Expected 1 errors
78102
Line 34: Unexpected errors ['generics_basic.py:34:5: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in concat: bad return type [bad-return-type]']
79103
Line 67: Unexpected errors ['generics_basic.py:67:5: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in test_concat_subtype: MyStr [assert-type]']
80104
Line 68: Unexpected errors ['generics_basic.py:68:17: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in test_concat_subtype: Function concat was called with the wrong arguments [wrong-arg-types]', 'generics_basic.py:68:5: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in test_concat_subtype: Any [assert-type]']
81-
Line 182: Unexpected errors ['generics_basic.py:182:5: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in test_my_iterable_any: Iterator[nothing] [assert-type]']
105+
Line 168: Unexpected errors ['generics_basic.py:168:8: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in <module>: argument "covariant" to TypeVar not supported yet [not-supported-yet]']
106+
Line 169: Unexpected errors ['generics_basic.py:169:8: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in <module>: argument "covariant" to TypeVar not supported yet [not-supported-yet]']
107+
Line 199: Unexpected errors ['generics_basic.py:199:5: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in test_my_iterable_any: Iterator[nothing] [assert-type]']
82108
"""
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
version = "pytype 2024.10.11"
2-
test_duration = 45.1
2+
test_duration = 45.2

conformance/results/results.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,13 @@ <h3>Python Type System Conformance Test Results</h3>
162162
<div class='tc-time'>2.5sec</div>
163163
</th>
164164
<th class='tc-header'><div class='tc-name'>pyright 1.1.389</div>
165-
<div class='tc-time'>2.6sec</div>
165+
<div class='tc-time'>2.5sec</div>
166166
</th>
167167
<th class='tc-header'><div class='tc-name'>pyre 0.9.23</div>
168-
<div class='tc-time'>4.4sec</div>
168+
<div class='tc-time'>4.3sec</div>
169169
</th>
170170
<th class='tc-header'><div class='tc-name'>pytype 2024.10.11</div>
171-
<div class='tc-time'>45.1sec</div>
171+
<div class='tc-time'>45.2sec</div>
172172
</th>
173173
</tr>
174174
<tr><th class="column" colspan="5">
@@ -249,8 +249,8 @@ <h3>Python Type System Conformance Test Results</h3>
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>
251251
<th class="column col2 conformant">Pass</th>
252-
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>False positives in examples using constrained type variables.</p><p>False negative for constraint parameterized by a type variable.</p><p>False negative in custom map example.</p><p>False positive using `iter`.</p><p>False negative for generic metaclass.</p></span></div></th>
253-
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>False positives in examples using constrained type variables.</p><p>False negative for generic metaclass.</p></span></div></th>
252+
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>False positives in examples using constrained type variables.</p><p>False negative for constraint parameterized by a type variable.</p><p>False negative in custom map example.</p><p>False positive using `iter`.</p><p>False negative for bad type arguments to Generic/Protocol.</p><p>False negative for generic metaclass.</p></span></div></th>
253+
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>False positives in examples using constrained type variables.</p><p>Argument 'covariant' to TypeVar not supported.</p><p>False negative for type variables missing from Generic/Protocol base class.</p><p>False negative for generic metaclass.</p></span></div></th>
254254
</tr>
255255
<tr><th class="column col1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;generics_defaults</th>
256256
<th class="column col2 not-conformant">Unsupported</th>

conformance/tests/generics_basic.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from __future__ import annotations
88

99
from collections.abc import Sequence
10-
from typing import Any, Generic, TypeVar, assert_type
10+
from typing import Any, Generic, Protocol, TypeVar, assert_type
1111

1212
T = TypeVar("T")
1313

@@ -157,6 +157,23 @@ def test_my_map(m1: MyMap1[str, int], m2: MyMap2[int, str]):
157157
m1[0] # E
158158
m2[0] # E
159159

160+
# > All arguments to ``Generic`` or ``Protocol`` must be type variables.
161+
162+
class Bad1(Generic[int]): ... # E
163+
class Bad2(Protocol[int]): ... # E
164+
165+
# > All type parameters for the class must appear within the ``Generic`` or
166+
# > ``Protocol`` type argument list.
167+
168+
T_co = TypeVar("T_co", covariant=True)
169+
S_co = TypeVar("S_co", covariant=True)
170+
171+
class Bad3(Iterable[T_co], Generic[S_co]): ... # E
172+
class Bad4(Iterable[T_co], Protocol[S_co]): ... # E
173+
174+
# > The above rule does not apply to a bare ``Protocol`` base class.
175+
176+
class MyIterator(Iterator[T_co], Protocol): ... # OK
160177

161178
# > You can use multiple inheritance with ``Generic``
162179

0 commit comments

Comments
 (0)