Skip to content

Commit 5f573e7

Browse files
committed
Conformance suite: update generics_upper_bound.py to not assume that [1, 2] will be inferred as list[int]
1 parent 80c55d2 commit 5f573e7

File tree

6 files changed

+33
-21
lines changed

6 files changed

+33
-21
lines changed

conformance/results/mypy/generics_upper_bound.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ Does not reject use of type variable within an upper bound.
44
"""
55
output = """
66
generics_upper_bound.py:43: error: Expression is of type "Collection[int]", not "list[int] | set[int]" [assert-type]
7-
generics_upper_bound.py:51: error: Value of type variable "ST" of "longer" cannot be "int" [type-var]
8-
generics_upper_bound.py:56: error: TypeVar cannot have both values and an upper bound [misc]
7+
generics_upper_bound.py:52: error: Value of type variable "ST" of "longer" cannot be "int" [type-var]
8+
generics_upper_bound.py:57: error: TypeVar cannot have both values and an upper bound [misc]
99
"""
1010
conformance_automated = "Fail"
1111
errors_diff = """
Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
1-
conformance_automated = "Pass"
1+
conformance_automated = "Fail"
2+
conformant = "Partial"
3+
notes = """
4+
Cannot find a common supertype of `list[int]` and `set[int]` in order to solve a type variable bound to `Sized`.
5+
"""
26
errors_diff = """
7+
Lines 43, 44: Expected exactly one error (tag 'mixed-collections')
8+
Line 43: Unexpected errors ['assert_type(list[int], list[int] | set[int]) failed [assert-type]', 'Argument `set[int]` is not assignable to parameter `y` with type `list[int]` in function `longer` [bad-argument-type]']
9+
Line 44: Unexpected errors ['assert_type(list[int], Collection[int]) failed [assert-type]', 'Argument `set[int]` is not assignable to parameter `y` with type `list[int]` in function `longer` [bad-argument-type]']
310
"""
411
output = """
512
ERROR generics_upper_bound.py:24:38-45: Type variable bounds and constraints must be concrete [invalid-annotation]
6-
ERROR generics_upper_bound.py:43:12-55: assert_type(list[int], list[int] | set[int]) failed [assert-type]
7-
ERROR generics_upper_bound.py:43:25-31: Argument `set[int]` is not assignable to parameter `y` with type `list[int]` in function `longer` [bad-argument-type]
8-
ERROR generics_upper_bound.py:51:7-13: `int` is not assignable to upper bound `Sized` of type variable `ST` [bad-specialization]
9-
ERROR generics_upper_bound.py:56:38-49: TypeVar cannot have both constraints and bound [invalid-type-var]
13+
ERROR generics_upper_bound.py:43:16-59: assert_type(list[int], list[int] | set[int]) failed [assert-type]
14+
ERROR generics_upper_bound.py:43:31-35: Argument `set[int]` is not assignable to parameter `y` with type `list[int]` in function `longer` [bad-argument-type]
15+
ERROR generics_upper_bound.py:44:16-54: assert_type(list[int], Collection[int]) failed [assert-type]
16+
ERROR generics_upper_bound.py:44:31-35: Argument `set[int]` is not assignable to parameter `y` with type `list[int]` in function `longer` [bad-argument-type]
17+
ERROR generics_upper_bound.py:52:7-13: `int` is not assignable to upper bound `Sized` of type variable `ST` [bad-specialization]
18+
ERROR generics_upper_bound.py:57:38-49: TypeVar cannot have both constraints and bound [invalid-type-var]
1019
"""

conformance/results/pyright/generics_upper_bound.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
conformant = "Pass"
22
output = """
33
generics_upper_bound.py:24:38 - error: TypeVar bound type cannot be generic (reportGeneralTypeIssues)
4-
generics_upper_bound.py:51:8 - error: Argument of type "Literal[3]" cannot be assigned to parameter "x" of type "ST@longer" in function "longer"
4+
generics_upper_bound.py:44:17 - error: "assert_type" mismatch: expected "Collection[int]" but received "list[int] | set[int]" (reportAssertTypeFailure)
5+
generics_upper_bound.py:52:8 - error: Argument of type "Literal[3]" cannot be assigned to parameter "x" of type "ST@longer" in function "longer"
56
  Type "Literal[3]" is not assignable to type "Sized"
67
    "Literal[3]" is incompatible with protocol "Sized"
78
      "__len__" is not present (reportArgumentType)
8-
generics_upper_bound.py:51:11 - error: Argument of type "Literal[3]" cannot be assigned to parameter "y" of type "ST@longer" in function "longer"
9+
generics_upper_bound.py:52:11 - error: Argument of type "Literal[3]" cannot be assigned to parameter "y" of type "ST@longer" in function "longer"
910
  Type "Literal[3]" is not assignable to type "Sized"
1011
    "Literal[3]" is incompatible with protocol "Sized"
1112
      "__len__" is not present (reportArgumentType)
12-
generics_upper_bound.py:56:44 - error: TypeVar cannot be both bound and constrained (reportGeneralTypeIssues)
13+
generics_upper_bound.py:57:44 - error: TypeVar cannot be both bound and constrained (reportGeneralTypeIssues)
1314
"""
1415
conformance_automated = "Pass"
1516
errors_diff = """

conformance/results/results.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ <h3>Python Type System Conformance Test Results</h3>
416416
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Does not reject use of type variable within an upper bound.</p></span></div></th>
417417
<th class="column col2 conformant">Pass</th>
418418
<th class="column col2 conformant">Pass</th>
419-
<th class="column col2 conformant">Pass</th>
419+
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Cannot find a common supertype of `list[int]` and `set[int]` in order to solve a type variable bound to `Sized`.</p></span></div></th>
420420
</tr>
421421
<tr><th class="column col1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;generics_variance</th>
422422
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Does not reject use of class-scoped TypeVar used in a base class when variance is incompatible.</p></span></div></th>

conformance/results/zuban/generics_upper_bound.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ errors_diff = """
33
"""
44
output = """
55
generics_upper_bound.py:24: error: TypeVar bound must not contain type variables [misc]
6-
generics_upper_bound.py:51: error: Value of type variable "ST" of "longer" cannot be "int" [type-var]
7-
generics_upper_bound.py:51: error: Value of type variable "ST" of "longer" cannot be "int" [type-var]
8-
generics_upper_bound.py:56: error: TypeVar cannot have both values and an upper bound [misc]
6+
generics_upper_bound.py:44: error: Expression is of type "list[int] | set[int]", not "Collection[int]" [misc]
7+
generics_upper_bound.py:52: error: Value of type variable "ST" of "longer" cannot be "int" [type-var]
8+
generics_upper_bound.py:52: error: Value of type variable "ST" of "longer" cannot be "int" [type-var]
9+
generics_upper_bound.py:57: error: TypeVar cannot have both values and an upper bound [misc]
910
"""

conformance/tests/generics_upper_bound.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,14 @@ def longer(x: ST, y: ST) -> ST:
3434
return y
3535

3636

37-
assert_type(longer([1], [1, 2]), list[int])
38-
assert_type(longer({1}, {1, 2}), set[int])
39-
40-
# Type checkers that use a join rather than a union (like mypy)
41-
# will produce Collection[int] here instead of list[int] | set[int].
42-
# Both answers are conformant with the spec.
43-
assert_type(longer([1], {1, 2}), list[int] | set[int]) # E?
37+
def f(list1: list[int], list2: list[int], set1: set[int], set2: set[int]):
38+
assert_type(longer(list1, list2), list[int])
39+
assert_type(longer(set1, set2), set[int])
40+
41+
# Either answer here is conformant with the spec;
42+
# exactly one should pass:
43+
assert_type(longer(list1, set1), list[int] | set[int]) # E[mixed-collections]
44+
assert_type(longer(list1, set1), Collection[int]) # E[mixed-collections]
4445

4546

4647
def requires_collection(c: Collection[int]) -> None: ...

0 commit comments

Comments
 (0)