You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
conformance: fix generics_defaults to flag ParamSpec-after-TypeVarTuple without TVT default
The conformance test for `class Foo6(Generic[*Ts, P])` was missing an
`# E` marker. The spec only permits a defaulted `ParamSpec` to follow a
`TypeVarTuple` when the `TypeVarTuple` **also has a default**; in the
test `Ts` had no default, so the class is ambiguous (exactly like the
`TypeVar`-after-`TypeVarTuple` rule) and raises `TypeError` at runtime.
Changes:
- Add `TsD = TypeVarTuple("TsD", default=Unpack[tuple[int, str]])` for
the valid case.
- Mark `class Foo6(Generic[*Ts, P])` as `# E` (Ts has no default).
- Add `class Foo6b(Generic[*TsD, P])` as the spec-valid case (both
`TsD` and `P` have defaults) with corresponding assertions.
- Clarify the spec prose to state the "TypeVarTuple **with a default**"
condition explicitly and show a counter-example.
- Update all six checker result TOMLs.
Fixes: #2211
Copy file name to clipboardExpand all lines: conformance/results/mypy/generics_defaults.toml
+8-7Lines changed: 8 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -10,15 +10,16 @@ generics_defaults.py:139: error: Expression is of type "tuple[*tuple[str, int],
10
10
generics_defaults.py:152: error: TypeVar default must be a subtype of the bound type [misc]
11
11
generics_defaults.py:159: error: TypeVar default must be one of the constraint types [misc]
12
12
generics_defaults.py:177: error: Expression is of type "int", not "Any" [assert-type]
13
-
generics_defaults.py:203: error: Can only replace ParamSpec with a parameter types list or another ParamSpec, got "str" [valid-type]
14
-
generics_defaults.py:204: error: Expression is of type "tuple[Any, ...]", not "tuple[int, str]" [assert-type]
15
-
generics_defaults.py:205: error: Expression is of type "def (*Any, **Any) -> None", not "Callable[[float, bool], None]" [assert-type]
13
+
generics_defaults.py:211: error: Can only replace ParamSpec with a parameter types list or another ParamSpec, got "str" [valid-type]
14
+
generics_defaults.py:212: error: Expression is of type "tuple[Any, ...]", not "tuple[int, str]" [assert-type]
15
+
generics_defaults.py:213: error: Expression is of type "def (*Any, **Any) -> None", not "Callable[[float, bool], None]" [assert-type]
16
16
"""
17
17
conformance_automated = "Fail"
18
18
errors_diff = """
19
-
Line 188: Expected 1 errors
19
+
Line 189: Expected 1 errors
20
+
Line 201: Expected 1 errors
20
21
Line 139: Unexpected errors ['generics_defaults.py:139: error: Expression is of type "tuple[*tuple[str, int], ...]", not "tuple[str, int]" [assert-type]']
21
-
Line 203: Unexpected errors ['generics_defaults.py:203: error: Can only replace ParamSpec with a parameter types list or another ParamSpec, got "str" [valid-type]']
22
-
Line 204: Unexpected errors ['generics_defaults.py:204: error: Expression is of type "tuple[Any, ...]", not "tuple[int, str]" [assert-type]']
23
-
Line 205: Unexpected errors ['generics_defaults.py:205: error: Expression is of type "def (*Any, **Any) -> None", not "Callable[[float, bool], None]" [assert-type]']
22
+
Line 211: Unexpected errors ['generics_defaults.py:211: error: Can only replace ParamSpec with a parameter types list or another ParamSpec, got "str" [valid-type]']
23
+
Line 212: Unexpected errors ['generics_defaults.py:212: error: Expression is of type "tuple[Any, ...]", not "tuple[int, str]" [assert-type]']
24
+
Line 213: Unexpected errors ['generics_defaults.py:213: error: Expression is of type "def (*Any, **Any) -> None", not "Callable[[float, bool], None]" [assert-type]']
Copy file name to clipboardExpand all lines: conformance/results/pycroscope/generics_defaults.toml
+11-10Lines changed: 11 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,7 @@ Numerous issues; does not support TypeVarTuple and ParamSpec defaults.
4
4
"""
5
5
conformance_automated = "Fail"
6
6
errors_diff = """
7
+
Line 201: Expected 1 errors
7
8
Line 33: Unexpected errors ['./generics_defaults.py:33:16: ~DefaultStrT@./generics_defaults.py.NoNonDefaults is not equivalent to str']
8
9
Line 34: Unexpected errors ['./generics_defaults.py:34:16: ~DefaultIntT@./generics_defaults.py.NoNonDefaults is not equivalent to int']
9
10
Line 73: Unexpected errors ['./generics_defaults.py:73:16: ~T1@./generics_defaults.py.AllTheDefaults is not equivalent to Any[explicit]']
@@ -14,10 +15,10 @@ Line 77: Unexpected errors ['./generics_defaults.py:77:16: ~DefaultBoolT@./gen
14
15
Line 122: Unexpected errors ['./generics_defaults.py:122:16: (**__P: **DefaultP@./generics_defaults.py.Class_ParamSpec) -> None is not equivalent to (str, int, /) -> None']
15
16
Line 124: Unexpected errors ['./generics_defaults.py:124:16: ./generics_defaults.py.Class_ParamSpec[AnySig()] is not equivalent to ./generics_defaults.py.Class_ParamSpec[tuple[bool, bool]]']
16
17
Line 144: Unexpected errors ['./generics_defaults.py:144:60: Incompatible argument type for default: expected TypeForm[object] but got Literal[typing.Unpack[DefaultTs]] [incompatible_argument]']
17
-
Line 203: Unexpected errors ["./generics_defaults.py:203:36: Invalid type annotation [<class 'bytes'>] [invalid_annotation]", './generics_defaults.py:203:17: ParamSpec specialization must use list form, Concatenate[..., P], P, or ... [invalid_annotation]']
18
-
Line 204: Unexpected errors ['./generics_defaults.py:204:16: tuple[int] is not equivalent to tuple[int, str]']
19
-
Line 205: Unexpected errors ['./generics_defaults.py:205:16: (...) -> None is not equivalent to (float | int, bool, /) -> None']
20
-
Line 208: Unexpected errors ['./generics_defaults.py:208:16: (...) -> None is not equivalent to (bytes, /) -> None']
18
+
Line 211: Unexpected errors ["./generics_defaults.py:211:38: Invalid type annotation [<class 'bytes'>] [invalid_annotation]", './generics_defaults.py:211:18: ParamSpec specialization must use list form, Concatenate[..., P], P, or ... [invalid_annotation]']
19
+
Line 212: Unexpected errors ['./generics_defaults.py:212:16: tuple[int] is not equivalent to tuple[int, str]']
20
+
Line 213: Unexpected errors ['./generics_defaults.py:213:16: (...) -> None is not equivalent to (float | int, bool, /) -> None']
21
+
Line 216: Unexpected errors ['./generics_defaults.py:216:16: (...) -> None is not equivalent to (bytes, /) -> None']
21
22
"""
22
23
output = """
23
24
./generics_defaults.py:24:0: non-default TypeVars cannot follow ones with defaults [invalid_type_parameter]
@@ -35,10 +36,10 @@ output = """
35
36
./generics_defaults.py:152:50: TypeVar default must be assignable to its bound [incompatible_call]
36
37
./generics_defaults.py:159:51: TypeVar default must be one of its constraints [incompatible_call]
37
38
./generics_defaults.py:176:12: Any[generic_argument] is not equivalent to int
38
-
./generics_defaults.py:188:0: TypeVars with defaults cannot follow TypeVarTuples [invalid_type_parameter]
39
-
./generics_defaults.py:203:36: Invalid type annotation [<class 'bytes'>] [invalid_annotation]
40
-
./generics_defaults.py:203:17: ParamSpec specialization must use list form, Concatenate[..., P], P, or ... [invalid_annotation]
41
-
./generics_defaults.py:204:16: tuple[int] is not equivalent to tuple[int, str]
42
-
./generics_defaults.py:205:16: (...) -> None is not equivalent to (float | int, bool, /) -> None
43
-
./generics_defaults.py:208:16: (...) -> None is not equivalent to (bytes, /) -> None
39
+
./generics_defaults.py:189:0: TypeVars with defaults cannot follow TypeVarTuples [invalid_type_parameter]
40
+
./generics_defaults.py:211:38: Invalid type annotation [<class 'bytes'>] [invalid_annotation]
41
+
./generics_defaults.py:211:18: ParamSpec specialization must use list form, Concatenate[..., P], P, or ... [invalid_annotation]
42
+
./generics_defaults.py:212:16: tuple[int] is not equivalent to tuple[int, str]
43
+
./generics_defaults.py:213:16: (...) -> None is not equivalent to (float | int, bool, /) -> None
44
+
./generics_defaults.py:216:16: (...) -> None is not equivalent to (bytes, /) -> None
<thclass="column col2 partially-conformant"><divclass="hover-text">Partial<spanclass="tooltip-text" id="bottom"><p>Does not detect a TypeVar with a default used after a TypeVarTuple.</p><p>Does not fully support defaults on TypeVarTuple and ParamSpec.</p></span></div></th>
<thclass="column col2 partially-conformant"><divclass="hover-text">Partial<spanclass="tooltip-text" id="bottom"><p>Numerous issues; does not support TypeVarTuple and ParamSpec defaults.</p></span></div></th>
310
310
<thclass="column col2 partially-conformant"><divclass="hover-text">Partial<spanclass="tooltip-text" id="bottom"><p>Does not forbid a `TypeVar` immediately following a `TypeVarTuple` in a parameter list from having a default.</p><p>Does not support `TypeVarTuple`.</p></span></div></th>
Copy file name to clipboardExpand all lines: conformance/results/ty/generics_defaults.toml
+14-11Lines changed: 14 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -5,14 +5,16 @@ Does not forbid a `TypeVar` immediately following a `TypeVarTuple` in a paramete
5
5
Does not support `TypeVarTuple`.
6
6
"""
7
7
errors_diff = """
8
-
Line 188: Expected 1 errors
8
+
Line 189: Expected 1 errors
9
+
Line 201: Expected 1 errors
9
10
Line 139: Unexpected errors ['generics_defaults.py:139:5: error[type-assertion-failure] Type `tuple[@Todo(TypeVarTuple), ...]` does not match asserted type `tuple[str, int]`']
10
11
Line 140: Unexpected errors ['generics_defaults.py:140:5: error[type-assertion-failure] Type `Class_TypeVarTuple` does not match asserted type `@Todo`']
11
-
Line 200: Unexpected errors ['generics_defaults.py:200:17: error[invalid-type-form] The first argument to `Callable` must be either a list of types, ParamSpec, Concatenate, or `...`']
12
-
Line 204: Unexpected errors ['generics_defaults.py:204:5: error[type-assertion-failure] Type `@Todo` does not match asserted type `tuple[int, str]`']
13
-
Line 205: Unexpected errors ['generics_defaults.py:205:5: error[type-assertion-failure] Type `@Todo` does not match asserted type `(int | float, bool, /) -> None`']
14
-
Line 207: Unexpected errors ['generics_defaults.py:207:5: error[type-assertion-failure] Type `@Todo` does not match asserted type `tuple[int, str]`']
15
-
Line 208: Unexpected errors ['generics_defaults.py:208:5: error[type-assertion-failure] Type `@Todo` does not match asserted type `(bytes, /) -> None`']
12
+
Line 203: Unexpected errors ['generics_defaults.py:203:17: error[invalid-type-form] The first argument to `Callable` must be either a list of types, ParamSpec, Concatenate, or `...`']
13
+
Line 208: Unexpected errors ['generics_defaults.py:208:17: error[invalid-type-form] The first argument to `Callable` must be either a list of types, ParamSpec, Concatenate, or `...`']
14
+
Line 212: Unexpected errors ['generics_defaults.py:212:5: error[type-assertion-failure] Type `@Todo` does not match asserted type `tuple[int, str]`']
15
+
Line 213: Unexpected errors ['generics_defaults.py:213:5: error[type-assertion-failure] Type `@Todo` does not match asserted type `(int | float, bool, /) -> None`']
16
+
Line 215: Unexpected errors ['generics_defaults.py:215:5: error[type-assertion-failure] Type `@Todo` does not match asserted type `tuple[int, str]`']
17
+
Line 216: Unexpected errors ['generics_defaults.py:216:5: error[type-assertion-failure] Type `@Todo` does not match asserted type `(bytes, /) -> None`']
16
18
"""
17
19
output = """
18
20
generics_defaults.py:24:40: error[invalid-generic-class] Type parameter `T` without a default cannot follow earlier parameter `DefaultStrT` with a default
@@ -22,9 +24,10 @@ generics_defaults.py:140:5: error[type-assertion-failure] Type `Class_TypeVarTup
22
24
generics_defaults.py:152:51: error[invalid-type-variable-default] TypeVar default is not assignable to the TypeVar's upper bound
23
25
generics_defaults.py:159:52: error[invalid-type-variable-default] TypeVar default is inconsistent with the TypeVar's constraints: `int` is not one of the constraints of `Invalid2`
24
26
generics_defaults.py:177:1: error[type-assertion-failure] Type `int` does not match asserted type `Any`
25
-
generics_defaults.py:200:17: error[invalid-type-form] The first argument to `Callable` must be either a list of types, ParamSpec, Concatenate, or `...`
26
-
generics_defaults.py:204:5: error[type-assertion-failure] Type `@Todo` does not match asserted type `tuple[int, str]`
27
-
generics_defaults.py:205:5: error[type-assertion-failure] Type `@Todo` does not match asserted type `(int | float, bool, /) -> None`
28
-
generics_defaults.py:207:5: error[type-assertion-failure] Type `@Todo` does not match asserted type `tuple[int, str]`
29
-
generics_defaults.py:208:5: error[type-assertion-failure] Type `@Todo` does not match asserted type `(bytes, /) -> None`
27
+
generics_defaults.py:203:17: error[invalid-type-form] The first argument to `Callable` must be either a list of types, ParamSpec, Concatenate, or `...`
28
+
generics_defaults.py:208:17: error[invalid-type-form] The first argument to `Callable` must be either a list of types, ParamSpec, Concatenate, or `...`
29
+
generics_defaults.py:212:5: error[type-assertion-failure] Type `@Todo` does not match asserted type `tuple[int, str]`
30
+
generics_defaults.py:213:5: error[type-assertion-failure] Type `@Todo` does not match asserted type `(int | float, bool, /) -> None`
31
+
generics_defaults.py:215:5: error[type-assertion-failure] Type `@Todo` does not match asserted type `tuple[int, str]`
32
+
generics_defaults.py:216:5: error[type-assertion-failure] Type `@Todo` does not match asserted type `(bytes, /) -> None`
0 commit comments