Skip to content

Commit b855865

Browse files
committed
[conformance] Add examples that require bidi inference of list literals after specialization inference
1 parent 94514b1 commit b855865

8 files changed

Lines changed: 162 additions & 32 deletions

File tree

conformance/results/mypy/constructors_callable.toml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ Line 107: Unexpected errors ['constructors_callable.py:107: error: Expression is
1515
Line 118: Unexpected errors ['constructors_callable.py:118: error: Incompatible return type for "__new__" (returns "Class6Proxy", but must return a subtype of "Class6") [misc]']
1616
Line 128: Unexpected errors ['constructors_callable.py:128: error: Expression is of type "Class6", not "Class6Proxy" [assert-type]', 'constructors_callable.py:128: error: Too few arguments [call-arg]']
1717
Line 145: Unexpected errors ['constructors_callable.py:145: error: Expression is of type "Class6Any", not "Any" [assert-type]', 'constructors_callable.py:145: error: Too few arguments [call-arg]']
18+
Line 187: Unexpected errors ['constructors_callable.py:187: error: Expression is of type "Class8[Any]", not "Class8[int | str]" [assert-type]', 'constructors_callable.py:187: error: Cannot infer function type argument [misc]']
19+
Line 199: Unexpected errors ['constructors_callable.py:199: error: Cannot infer function type argument [misc]']
20+
Line 215: Unexpected errors ['constructors_callable.py:215: error: Expression is of type "Class10[Any]", not "Class10[int]" [assert-type]', 'constructors_callable.py:215: error: Cannot infer function type argument [misc]']
21+
Line 229: Unexpected errors ['constructors_callable.py:229: error: Cannot infer function type argument [misc]']
1822
"""
1923
output = """
2024
constructors_callable.py:36: note: Revealed type is "def (x: int) -> constructors_callable.Class1"
@@ -43,7 +47,19 @@ constructors_callable.py:145: error: Expression is of type "Class6Any", not "Any
4347
constructors_callable.py:145: error: Too few arguments [call-arg]
4448
constructors_callable.py:164: note: Revealed type is "Overload(def (x: int) -> constructors_callable.Class7[int], def (x: str) -> constructors_callable.Class7[str])"
4549
constructors_callable.py:184: note: Revealed type is "def [T] (x: list[T], y: list[T]) -> constructors_callable.Class8[T]"
46-
constructors_callable.py:186: error: Cannot infer function type argument [misc]
47-
constructors_callable.py:195: note: Revealed type is "def [T] (x: list[T], y: list[T]) -> constructors_callable.Class9"
48-
constructors_callable.py:197: error: Cannot infer function type argument [misc]
50+
constructors_callable.py:185: error: Argument 2 has incompatible type "str"; expected "list[str]" [arg-type]
51+
constructors_callable.py:187: error: Expression is of type "Class8[Any]", not "Class8[int | str]" [assert-type]
52+
constructors_callable.py:187: error: Cannot infer function type argument [misc]
53+
constructors_callable.py:196: note: Revealed type is "def [T] (x: list[T], y: list[T]) -> constructors_callable.Class9"
54+
constructors_callable.py:197: error: Argument 2 has incompatible type "str"; expected "list[str]" [arg-type]
55+
constructors_callable.py:199: error: Cannot infer function type argument [misc]
56+
constructors_callable.py:210: note: Revealed type is "def [T_int <: int] (x: list[T_int], y: list[T_int]) -> constructors_callable.Class10[T_int]"
57+
constructors_callable.py:211: error: Argument 2 has incompatible type "str"; expected "list[int]" [arg-type]
58+
constructors_callable.py:212: error: Cannot infer function type argument [misc]
59+
constructors_callable.py:215: error: Expression is of type "Class10[Any]", not "Class10[int]" [assert-type]
60+
constructors_callable.py:215: error: Cannot infer function type argument [misc]
61+
constructors_callable.py:224: note: Revealed type is "def [T_int <: int] (x: list[T_int], y: list[T_int]) -> constructors_callable.Class11"
62+
constructors_callable.py:225: error: Argument 2 has incompatible type "str"; expected "list[int]" [arg-type]
63+
constructors_callable.py:226: error: Cannot infer function type argument [misc]
64+
constructors_callable.py:229: error: Cannot infer function type argument [misc]
4965
"""

conformance/results/pycroscope/constructors_callable.toml

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
conformance_automated = "Pass"
1+
conformant = "Partial"
2+
notes = """
3+
List literal arguments are inferred in isolation before specialization inference
4+
"""
5+
conformance_automated = "Fail"
26
errors_diff = """
7+
Line 187: Unexpected errors ['./constructors_callable.py:187:12: ./constructors_callable.py.Class8[Any[error]] is not equivalent to ./constructors_callable.py.Class8[int | str]', './constructors_callable.py:187:12: Cannot resolve type variables [incompatible_call]']
8+
Line 199: Unexpected errors ['./constructors_callable.py:199:12: Cannot resolve type variables [incompatible_call]']
39
"""
410
output = """
511
./constructors_callable.py:36:12: Revealed type is '(x: int) -> ./constructors_callable.py.Class1' [reveal_type]
@@ -21,7 +27,16 @@ output = """
2127
./constructors_callable.py:146:0: Takes 0 positional arguments but 1 were given [incompatible_call]
2228
./constructors_callable.py:164:4: Revealed type is '(x: ~_Ctor_Class7_T) -> ./constructors_callable.py.Class7[~_Ctor_Class7_T]' [reveal_type]
2329
./constructors_callable.py:184:12: Revealed type is '(x: list[~T@./constructors_callable.py.Class8], y: list[~T@./constructors_callable.py.Class8]) -> ./constructors_callable.py.Class8[~T@./constructors_callable.py.Class8]' [reveal_type]
24-
./constructors_callable.py:186:0: Cannot resolve type variables [incompatible_call]
25-
./constructors_callable.py:195:12: Revealed type is '(x: list[~T@./constructors_callable.py.Class9.__init__.<locals>.__init__], y: list[~T@./constructors_callable.py.Class9.__init__.<locals>.__init__]) -> ./constructors_callable.py.Class9' [reveal_type]
26-
./constructors_callable.py:197:0: Cannot resolve type variables [incompatible_call]
30+
./constructors_callable.py:185:9: Incompatible argument type for y: expected list[~T@./constructors_callable.py.Class8] but got Literal['not a list'] [incompatible_argument]
31+
./constructors_callable.py:187:12: ./constructors_callable.py.Class8[Any[error]] is not equivalent to ./constructors_callable.py.Class8[int | str]
32+
./constructors_callable.py:187:12: Cannot resolve type variables [incompatible_call]
33+
./constructors_callable.py:196:12: Revealed type is '(x: list[~T@./constructors_callable.py.Class9.__init__.<locals>.__init__], y: list[~T@./constructors_callable.py.Class9.__init__.<locals>.__init__]) -> ./constructors_callable.py.Class9' [reveal_type]
34+
./constructors_callable.py:197:9: Incompatible argument type for y: expected list[~T@./constructors_callable.py.Class9.__init__.<locals>.__init__] but got Literal['not a list'] [incompatible_argument]
35+
./constructors_callable.py:199:12: Cannot resolve type variables [incompatible_call]
36+
./constructors_callable.py:210:12: Revealed type is '(x: list[~T_int@./constructors_callable.py.Class10], y: list[~T_int@./constructors_callable.py.Class10]) -> ./constructors_callable.py.Class10[~T_int@./constructors_callable.py.Class10]' [reveal_type]
37+
./constructors_callable.py:211:9: Incompatible argument type for y: expected list[~T_int@./constructors_callable.py.Class10] but got Literal['not a list'] [incompatible_argument]
38+
./constructors_callable.py:212:9: Incompatible argument type for y: expected list[~T_int@./constructors_callable.py.Class10] but got Literal[['']] [incompatible_argument]
39+
./constructors_callable.py:224:12: Revealed type is '(x: list[~T_int@./constructors_callable.py.Class11.__init__.<locals>.__init__], y: list[~T_int@./constructors_callable.py.Class11.__init__.<locals>.__init__]) -> ./constructors_callable.py.Class11' [reveal_type]
40+
./constructors_callable.py:225:9: Incompatible argument type for y: expected list[~T_int@./constructors_callable.py.Class11.__init__.<locals>.__init__] but got Literal['not a list'] [incompatible_argument]
41+
./constructors_callable.py:226:9: Incompatible argument type for y: expected list[~T_int@./constructors_callable.py.Class11.__init__.<locals>.__init__] but got Literal[['']] [incompatible_argument]
2742
"""

conformance/results/pyrefly/constructors_callable.toml

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@ Converting constructor to callable does not preserve class-scoped type params.
44
"""
55
conformance_automated = "Fail"
66
errors_diff = """
7-
Line 186: Expected 1 errors
8-
Line 185: Unexpected errors ['assert_type(Class8[Unknown], Class8[str]) failed [assert-type]']
7+
Line 212: Expected 1 errors
8+
Line 186: Unexpected errors ['assert_type(Class8[Unknown], Class8[str]) failed [assert-type]']
9+
Line 187: Unexpected errors ['assert_type(Class8[Unknown], Class8[int | str]) failed [assert-type]']
10+
Line 199: Unexpected errors ['Argument `list[str]` is not assignable to parameter `y` with type `list[int]` [bad-argument-type]']
11+
Line 213: Unexpected errors ['assert_type(Class10[Unknown], Class10[int]) failed [assert-type]']
12+
Line 214: Unexpected errors ['assert_type(Class10[Unknown], Class10[bool]) failed [assert-type]']
13+
Line 215: Unexpected errors ['assert_type(Class10[Unknown], Class10[int]) failed [assert-type]']
914
"""
1015
output = """
1116
ERROR constructors_callable.py:38:3-5: Missing argument `x` [missing-argument]
@@ -21,6 +26,16 @@ ERROR constructors_callable.py:82:3-8: Missing argument `x` [missing-argument]
2126
ERROR constructors_callable.py:82:4-5: Unexpected keyword argument `y` [unexpected-keyword]
2227
ERROR constructors_callable.py:129:4-5: Expected 0 positional arguments, got 1 [bad-argument-count]
2328
ERROR constructors_callable.py:146:8-9: Expected 0 positional arguments, got 1 [bad-argument-count]
24-
ERROR constructors_callable.py:185:12-41: assert_type(Class8[Unknown], Class8[str]) failed [assert-type]
25-
ERROR constructors_callable.py:197:9-13: Argument `list[str]` is not assignable to parameter `y` with type `list[int]` [bad-argument-type]
29+
ERROR constructors_callable.py:185:10-22: Argument `Literal['not a list']` is not assignable to parameter `y` with type `list[Unknown]` [bad-argument-type]
30+
ERROR constructors_callable.py:186:12-41: assert_type(Class8[Unknown], Class8[str]) failed [assert-type]
31+
ERROR constructors_callable.py:187:12-46: assert_type(Class8[Unknown], Class8[int | str]) failed [assert-type]
32+
ERROR constructors_callable.py:197:10-22: Argument `Literal['not a list']` is not assignable to parameter `y` with type `list[str]` [bad-argument-type]
33+
ERROR constructors_callable.py:199:21-25: Argument `list[str]` is not assignable to parameter `y` with type `list[int]` [bad-argument-type]
34+
ERROR constructors_callable.py:211:10-22: Argument `Literal['not a list']` is not assignable to parameter `y` with type `list[Unknown]` [bad-argument-type]
35+
ERROR constructors_callable.py:213:12-41: assert_type(Class10[Unknown], Class10[int]) failed [assert-type]
36+
ERROR constructors_callable.py:214:12-48: assert_type(Class10[Unknown], Class10[bool]) failed [assert-type]
37+
ERROR constructors_callable.py:215:12-44: assert_type(Class10[Unknown], Class10[int]) failed [assert-type]
38+
ERROR constructors_callable.py:225:10-22: Argument `Literal['not a list']` is not assignable to parameter `y` with type `list[int]` [bad-argument-type]
39+
ERROR constructors_callable.py:226:4-15: `str` is not assignable to upper bound `int` of type variable `T_int` [bad-specialization]
40+
ERROR constructors_callable.py:226:10-14: Argument `list[str]` is not assignable to parameter `y` with type `list[int]` [bad-argument-type]
2641
"""

conformance/results/pyright/constructors_callable.toml

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
conformant = "Pass"
2-
conformance_automated = "Pass"
1+
conformant = "Partial"
2+
notes = """
3+
List literal arguments are inferred in isolation before specialization inference
4+
"""
5+
conformance_automated = "Fail"
36
errors_diff = """
7+
Line 187: Unexpected errors ['constructors_callable.py:187:13 - error: "assert_type" mismatch: expected "Class8[int | str]" but received "Class8[int]" (reportAssertTypeFailure)', 'constructors_callable.py:187:22 - error: Argument of type "list[str]" cannot be assigned to parameter "y" of type "list[T@Class8]"']
8+
Line 199: Unexpected errors ['constructors_callable.py:199:22 - error: Argument of type "list[str]" cannot be assigned to parameter "y" of type "list[T@__init__]"']
49
"""
510
output = """
611
constructors_callable.py:36:13 - information: Type of "r1" is "(x: int) -> Class1"
@@ -25,9 +30,24 @@ constructors_callable.py:144:13 - information: Type of "r6_any" is "() -> Any"
2530
constructors_callable.py:146:8 - error: Expected 0 positional arguments (reportCallIssue)
2631
constructors_callable.py:164:5 - information: Type of "r7" is "Overload[(x: int) -> Class7[int], (x: str) -> Class7[str]]"
2732
constructors_callable.py:184:13 - information: Type of "r8" is "(x: list[T@Class8], y: list[T@Class8]) -> Class8[T@Class8]"
28-
constructors_callable.py:186:10 - error: Argument of type "list[str]" cannot be assigned to parameter "y" of type "list[T@Class8]"
33+
constructors_callable.py:185:10 - error: Argument of type "Literal['not a list']" cannot be assigned to parameter "y" of type "list[T@Class8]"
34+
  "Literal['not a list']" is not assignable to "list[str]" (reportArgumentType)
35+
constructors_callable.py:187:13 - error: "assert_type" mismatch: expected "Class8[int | str]" but received "Class8[int]" (reportAssertTypeFailure)
36+
constructors_callable.py:187:22 - error: Argument of type "list[str]" cannot be assigned to parameter "y" of type "list[T@Class8]"
37+
  "Literal['']" is not assignable to "int" (reportArgumentType)
38+
constructors_callable.py:196:13 - information: Type of "r9" is "(x: list[T@__init__], y: list[T@__init__]) -> Class9"
39+
constructors_callable.py:197:10 - error: Argument of type "Literal['not a list']" cannot be assigned to parameter "y" of type "list[T@__init__]"
40+
  "Literal['not a list']" is not assignable to "list[str]" (reportArgumentType)
41+
constructors_callable.py:199:22 - error: Argument of type "list[str]" cannot be assigned to parameter "y" of type "list[T@__init__]"
42+
  "Literal['']" is not assignable to "int" (reportArgumentType)
43+
constructors_callable.py:210:13 - information: Type of "r10" is "(x: list[T_int@Class10], y: list[T_int@Class10]) -> Class10[T_int@Class10]"
44+
constructors_callable.py:211:10 - error: Argument of type "Literal['not a list']" cannot be assigned to parameter "y" of type "list[T_int@Class10]"
45+
  "Literal['not a list']" is not assignable to "list[int]" (reportArgumentType)
46+
constructors_callable.py:212:11 - error: Argument of type "list[str]" cannot be assigned to parameter "y" of type "list[T_int@Class10]"
2947
  "Literal['']" is not assignable to "int" (reportArgumentType)
30-
constructors_callable.py:195:13 - information: Type of "r9" is "(x: list[T@__init__], y: list[T@__init__]) -> Class9"
31-
constructors_callable.py:197:10 - error: Argument of type "list[str]" cannot be assigned to parameter "y" of type "list[T@__init__]"
48+
constructors_callable.py:224:13 - information: Type of "r11" is "(x: list[T_int@__init__], y: list[T_int@__init__]) -> Class11"
49+
constructors_callable.py:225:10 - error: Argument of type "Literal['not a list']" cannot be assigned to parameter "y" of type "list[T_int@__init__]"
50+
  "Literal['not a list']" is not assignable to "list[int]" (reportArgumentType)
51+
constructors_callable.py:226:11 - error: Argument of type "list[str]" cannot be assigned to parameter "y" of type "list[T_int@__init__]"
3252
  "Literal['']" is not assignable to "int" (reportArgumentType)
3353
"""

conformance/results/results.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -828,11 +828,11 @@ <h3>Python Type System Conformance Test Results</h3>
828828
</tr>
829829
<tr><th class="column col1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;constructors_callable</th>
830830
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Does not generate a union type for __new__ and __init__ when converting class to callable.</p><p>Does not ignore __init__ based on __new__ return type when converting class to callable.</p><p>Does not support __new__ return type that is different from class being constructed.</p></span></div></th>
831-
<th class="column col2 conformant">Pass</th>
832-
<th class="column col2 conformant">Pass</th>
831+
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>List literal arguments are inferred in isolation before specialization inference</p></span></div></th>
832+
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>List literal arguments are inferred in isolation before specialization inference</p></span></div></th>
833833
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Converting constructor to callable does not preserve class-scoped type params.</p></span></div></th>
834-
<th class="column col2 conformant">Pass</th>
835-
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Does not include `__init__` when `__new__` returns `Self`.</p><p>Does not respect `NoReturn` return type on metaclass `__call__`.</p><p>Does not ignore `__init__` when `__new__` returns `Any`.</p><p>Unions overload return types.</p></span></div></th>
834+
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>List literal arguments are inferred in isolation before specialization inference</p></span></div></th>
835+
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Does not include `__init__` when `__new__` returns `Self`.</p><p>Does not respect `NoReturn` return type on metaclass `__call__`.</p><p>Does not ignore `__init__` when `__new__` returns `Any`.</p><p>Unions overload return types.</p><p>List literal arguments are inferred in isolation before specialization inference</p></span></div></th>
836836
</tr>
837837
<tr><th class="column col1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;constructors_consistency</th>
838838
<th class="column col2 conformant"><div class="hover-text">Pass*<span class="tooltip-text" id="bottom"><p>Does not report inconsistency between __new__ and __init__ (optional).</p></span></div></th>

0 commit comments

Comments
 (0)