Skip to content

Commit f9664d8

Browse files
authored
[conformance] Allow bidi inference of list literals after specialization inference (#2300)
1 parent ecfd695 commit f9664d8

14 files changed

Lines changed: 134 additions & 24 deletions

conformance/results/mypy/constructors_callable.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ constructors_callable.py:145: error: Expression is of type "Class6Any", not "Any
4343
constructors_callable.py:145: error: Too few arguments [call-arg]
4444
constructors_callable.py:164: note: Revealed type is "Overload(def (x: int) -> constructors_callable.Class7[int], def (x: str) -> constructors_callable.Class7[str])"
4545
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]
46+
constructors_callable.py:185: error: Argument 2 has incompatible type "str"; expected "list[str]" [arg-type]
47+
constructors_callable.py:187: error: Cannot infer function type argument [misc]
48+
constructors_callable.py:196: note: Revealed type is "def [T] (x: list[T], y: list[T]) -> constructors_callable.Class9"
49+
constructors_callable.py:197: error: Argument 2 has incompatible type "str"; expected "list[str]" [arg-type]
50+
constructors_callable.py:199: error: Cannot infer function type argument [misc]
4951
"""

conformance/results/mypy/generics_basic.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ generics_basic.py:208: error: Dynamic metaclass not supported for "GenericMetaIn
1616
generics_basic.py:208: error: Type variable "generics_basic.T" is unbound [valid-type]
1717
generics_basic.py:208: note: (Hint: Use "Generic[T]" or "Protocol[T]" base class to bind "T" inside a class)
1818
generics_basic.py:208: note: (Hint: Use "T" in function signature to bind "T" inside a function)
19+
generics_basic.py:223: error: Argument 2 to "takes_two_lists" has incompatible type "str"; expected "list[int]" [arg-type]
20+
generics_basic.py:225: error: Cannot infer value of type parameter "T" of "takes_two_lists" [misc]
21+
generics_basic.py:232: error: Cannot infer value of type parameter "T" of "takes_two_lists" [misc]
22+
generics_basic.py:240: error: Argument 2 to "takes_two_int_lists" has incompatible type "str"; expected "list[int]" [arg-type]
23+
generics_basic.py:241: error: Cannot infer value of type parameter "T_int" of "takes_two_int_lists" [misc]
24+
generics_basic.py:244: error: Cannot infer value of type parameter "T_int" of "takes_two_int_lists" [misc]
25+
generics_basic.py:251: error: Cannot infer value of type parameter "T_int" of "takes_two_int_lists" [misc]
1926
"""
2027
conformance_automated = "Pass"
2128
errors_diff = """

conformance/results/pycroscope/constructors_callable.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ output = """
2121
./constructors_callable.py:146:0: Takes 0 positional arguments but 1 were given [incompatible_call]
2222
./constructors_callable.py:164:4: Revealed type is '(x: ~_Ctor_Class7_T) -> ./constructors_callable.py.Class7[~_Ctor_Class7_T]' [reveal_type]
2323
./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]
24+
./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]
25+
./constructors_callable.py:187:0: Cannot resolve type variables [incompatible_call]
26+
./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]
27+
./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]
28+
./constructors_callable.py:199:0: Cannot resolve type variables [incompatible_call]
2729
"""

conformance/results/pycroscope/generics_basic.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,10 @@ output = """
1515
./generics_basic.py:171:27: All type parameters for the class must appear within Generic or Protocol [invalid_base]
1616
./generics_basic.py:172:27: All type parameters for the class must appear within Generic or Protocol [invalid_base]
1717
./generics_basic.py:208:36: Cannot determine metaclass [invalid_metaclass]
18+
./generics_basic.py:223:21: Incompatible argument type for y: expected list[~T@./generics_basic.py.takes_two_lists.<locals>.takes_two_lists] but got Literal['not a list'] [incompatible_argument]
19+
./generics_basic.py:225:0: Cannot resolve type variables [incompatible_call]
20+
./generics_basic.py:232:4: Cannot resolve type variables [incompatible_call]
21+
./generics_basic.py:240:25: Incompatible argument type for y: expected list[~T_int@./generics_basic.py.takes_two_int_lists.<locals>.takes_two_int_lists] but got Literal['not a list'] [incompatible_argument]
22+
./generics_basic.py:241:25: Incompatible argument type for y: expected list[~T_int@./generics_basic.py.takes_two_int_lists.<locals>.takes_two_int_lists] but got Literal[['']] [incompatible_argument]
23+
./generics_basic.py:251:4: Cannot resolve type variables [incompatible_call]
1824
"""

conformance/results/pyrefly/constructors_callable.toml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ 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 186: Unexpected errors ['assert_type(Class8[Unknown], Class8[str]) failed [assert-type]']
98
"""
109
output = """
1110
ERROR constructors_callable.py:38:3-5: Missing argument `x` [missing-argument]
@@ -21,6 +20,8 @@ ERROR constructors_callable.py:82:3-8: Missing argument `x` [missing-argument]
2120
ERROR constructors_callable.py:82:4-5: Unexpected keyword argument `y` [unexpected-keyword]
2221
ERROR constructors_callable.py:129:4-5: Expected 0 positional arguments, got 1 [bad-argument-count]
2322
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]
23+
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]
24+
ERROR constructors_callable.py:186:12-41: assert_type(Class8[Unknown], Class8[str]) failed [assert-type]
25+
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]
26+
ERROR constructors_callable.py:199:9-13: Argument `list[str]` is not assignable to parameter `y` with type `list[int]` [bad-argument-type]
2627
"""

conformance/results/pyrefly/generics_basic.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,11 @@ ERROR generics_basic.py:163:7-11: Expected a type variable, got `int` [invalid-t
1515
ERROR generics_basic.py:171:7-11: Class `Bad3` uses type variables not specified in `Generic` or `Protocol` base [invalid-type-var]
1616
ERROR generics_basic.py:172:7-11: Class `Bad4` uses type variables not specified in `Generic` or `Protocol` base [invalid-type-var]
1717
ERROR generics_basic.py:208:7-26: Metaclass may not be an unbound generic [invalid-inheritance]
18+
ERROR generics_basic.py:223:22-34: Argument `Literal['not a list']` is not assignable to parameter `y` with type `list[int]` in function `takes_two_lists` [bad-argument-type]
19+
ERROR generics_basic.py:225:22-26: Argument `list[str]` is not assignable to parameter `y` with type `list[int]` in function `takes_two_lists` [bad-argument-type]
20+
ERROR generics_basic.py:232:24-25: Argument `list[str]` is not assignable to parameter `y` with type `list[int]` in function `takes_two_lists` [bad-argument-type]
21+
ERROR generics_basic.py:240:26-38: Argument `Literal['not a list']` is not assignable to parameter `y` with type `list[int]` in function `takes_two_int_lists` [bad-argument-type]
22+
ERROR generics_basic.py:241:20-31: `str` is not assignable to upper bound `int` of type variable `T_int` [bad-specialization]
23+
ERROR generics_basic.py:241:26-30: Argument `list[str]` is not assignable to parameter `y` with type `list[int]` in function `takes_two_int_lists` [bad-argument-type]
24+
ERROR generics_basic.py:251:28-29: Argument `list[bool]` is not assignable to parameter `y` with type `list[int]` in function `takes_two_int_lists` [bad-argument-type]
1825
"""

conformance/results/pyright/constructors_callable.toml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
conformant = "Pass"
21
conformance_automated = "Pass"
32
errors_diff = """
43
"""
@@ -25,9 +24,13 @@ constructors_callable.py:144:13 - information: Type of "r6_any" is "() -> Any"
2524
constructors_callable.py:146:8 - error: Expected 0 positional arguments (reportCallIssue)
2625
constructors_callable.py:164:5 - information: Type of "r7" is "Overload[(x: int) -> Class7[int], (x: str) -> Class7[str]]"
2726
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]"
27+
constructors_callable.py:185:10 - error: Argument of type "Literal['not a list']" cannot be assigned to parameter "y" of type "list[T@Class8]"
28+
  "Literal['not a list']" is not assignable to "list[str]" (reportArgumentType)
29+
constructors_callable.py:187:10 - error: Argument of type "list[str]" cannot be assigned to parameter "y" of type "list[T@Class8]"
2930
  "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__]"
31+
constructors_callable.py:196:13 - information: Type of "r9" is "(x: list[T@__init__], y: list[T@__init__]) -> Class9"
32+
constructors_callable.py:197:10 - error: Argument of type "Literal['not a list']" cannot be assigned to parameter "y" of type "list[T@__init__]"
33+
  "Literal['not a list']" is not assignable to "list[str]" (reportArgumentType)
34+
constructors_callable.py:199:10 - error: Argument of type "list[str]" cannot be assigned to parameter "y" of type "list[T@__init__]"
3235
  "Literal['']" is not assignable to "int" (reportArgumentType)
3336
"""

conformance/results/pyright/generics_basic.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,22 @@ generics_basic.py:171:7 - error: Generic[] or Protocol[] must include all type v
2020
generics_basic.py:172:7 - error: Generic[] or Protocol[] must include all type variables
2121
  Missing type variables: "T_co" (reportGeneralTypeIssues)
2222
generics_basic.py:208:37 - error: Metaclass cannot be generic (reportGeneralTypeIssues)
23+
generics_basic.py:223:22 - error: Argument of type "Literal['not a list']" cannot be assigned to parameter "y" of type "list[T@takes_two_lists]" in function "takes_two_lists"
24+
  "Literal['not a list']" is not assignable to "list[int]" (reportArgumentType)
25+
generics_basic.py:225:23 - error: Argument of type "list[str]" cannot be assigned to parameter "y" of type "list[T@takes_two_lists]" in function "takes_two_lists"
26+
  "Literal['']" is not assignable to "int" (reportArgumentType)
27+
generics_basic.py:232:24 - error: Argument of type "list[str]" cannot be assigned to parameter "y" of type "list[T@takes_two_lists]" in function "takes_two_lists"
28+
  "list[str]" is not assignable to "list[int]"
29+
    Type parameter "_T@list" is invariant, but "str" is not the same as "int"
30+
    Consider switching from "list" to "Sequence" which is covariant (reportArgumentType)
31+
generics_basic.py:240:26 - error: Argument of type "Literal['not a list']" cannot be assigned to parameter "y" of type "list[T_int@takes_two_int_lists]" in function "takes_two_int_lists"
32+
  "Literal['not a list']" is not assignable to "list[int]" (reportArgumentType)
33+
generics_basic.py:241:27 - error: Argument of type "list[str]" cannot be assigned to parameter "y" of type "list[T_int@takes_two_int_lists]" in function "takes_two_int_lists"
34+
  "Literal['']" is not assignable to "int" (reportArgumentType)
35+
generics_basic.py:251:28 - error: Argument of type "list[bool]" cannot be assigned to parameter "y" of type "list[T_int@takes_two_int_lists]" in function "takes_two_int_lists"
36+
  "list[bool]" is not assignable to "list[int]"
37+
    Type parameter "_T@list" is invariant, but "bool" is not the same as "int"
38+
    Consider switching from "list" to "Sequence" which is covariant (reportArgumentType)
2339
"""
2440
conformance_automated = "Pass"
2541
errors_diff = """

conformance/results/ty/constructors_callable.toml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,11 @@ constructors_callable.py:164:5: info[revealed-type] Revealed type: `Overload[[T]
4242
constructors_callable.py:166:1: error[type-assertion-failure] Type `Class7[int] | Class7[str]` does not match asserted type `Class7[int]`
4343
constructors_callable.py:167:1: error[type-assertion-failure] Type `Class7[int] | Class7[str]` does not match asserted type `Class7[str]`
4444
constructors_callable.py:184:13: info[revealed-type] Revealed type: `[T](x: list[T], y: list[T]) -> Class8[T]`
45-
constructors_callable.py:186:4: error[invalid-argument-type] Argument is incorrect: Expected `list[int | str]`, found `list[int]`
46-
constructors_callable.py:186:9: error[invalid-argument-type] Argument is incorrect: Expected `list[int | str]`, found `list[str]`
47-
constructors_callable.py:195:13: info[revealed-type] Revealed type: `[T](x: list[T], y: list[T]) -> Class9`
48-
constructors_callable.py:197:4: error[invalid-argument-type] Argument is incorrect: Expected `list[int | str]`, found `list[int]`
49-
constructors_callable.py:197:9: error[invalid-argument-type] Argument is incorrect: Expected `list[int | str]`, found `list[str]`
45+
constructors_callable.py:185:10: error[invalid-argument-type] Argument is incorrect: Expected `list[str]`, found `Literal["not a list"]`
46+
constructors_callable.py:187:4: error[invalid-argument-type] Argument is incorrect: Expected `list[int | str]`, found `list[int]`
47+
constructors_callable.py:187:9: error[invalid-argument-type] Argument is incorrect: Expected `list[int | str]`, found `list[str]`
48+
constructors_callable.py:196:13: info[revealed-type] Revealed type: `[T](x: list[T], y: list[T]) -> Class9`
49+
constructors_callable.py:197:10: error[invalid-argument-type] Argument is incorrect: Expected `list[str]`, found `Literal["not a list"]`
50+
constructors_callable.py:199:4: error[invalid-argument-type] Argument is incorrect: Expected `list[int | str]`, found `list[int]`
51+
constructors_callable.py:199:9: error[invalid-argument-type] Argument is incorrect: Expected `list[int | str]`, found `list[str]`
5052
"""

conformance/results/ty/generics_basic.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,14 @@ generics_basic.py:163:12: error[invalid-argument-type] `<class 'int'>` is not a
1919
generics_basic.py:171:1: error[invalid-generic-class] `Generic` base class must include all type variables used in other base classes
2020
generics_basic.py:172:1: error[invalid-generic-class] `Generic` base class must include all type variables used in other base classes
2121
generics_basic.py:208:27: error[invalid-metaclass] Generic metaclasses are not supported
22+
generics_basic.py:223:22: error[invalid-argument-type] Argument to function `takes_two_lists` is incorrect: Expected `list[int]`, found `Literal["not a list"]`
23+
generics_basic.py:225:17: error[invalid-argument-type] Argument to function `takes_two_lists` is incorrect: Expected `list[int | str]`, found `list[int]`
24+
generics_basic.py:225:22: error[invalid-argument-type] Argument to function `takes_two_lists` is incorrect: Expected `list[int | str]`, found `list[str]`
25+
generics_basic.py:232:21: error[invalid-argument-type] Argument to function `takes_two_lists` is incorrect: Expected `list[int | str]`, found `list[int]`
26+
generics_basic.py:232:24: error[invalid-argument-type] Argument to function `takes_two_lists` is incorrect: Expected `list[int | str]`, found `list[str]`
27+
generics_basic.py:240:26: error[invalid-argument-type] Argument to function `takes_two_int_lists` is incorrect: Expected `list[int]`, found `Literal["not a list"]`
28+
generics_basic.py:241:26: error[invalid-argument-type] Argument to function `takes_two_int_lists` is incorrect: Argument type `str` does not satisfy upper bound `int` of type variable `T_int`
29+
generics_basic.py:241:26: error[invalid-argument-type] Argument to function `takes_two_int_lists` is incorrect: Expected `list[int]`, found `list[str]`
30+
generics_basic.py:244:26: error[invalid-argument-type] Argument to function `takes_two_int_lists` is incorrect: Expected `list[int]`, found `list[bool]`
31+
generics_basic.py:251:28: error[invalid-argument-type] Argument to function `takes_two_int_lists` is incorrect: Expected `list[int]`, found `list[bool]`
2232
"""

0 commit comments

Comments
 (0)