Skip to content

Commit 81ba400

Browse files
committed
specify that parameter specification should have variance
1 parent 418094f commit 81ba400

File tree

8 files changed

+165
-19
lines changed

8 files changed

+165
-19
lines changed

conformance/results/mypy/generics_paramspec_semantics.toml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
conformant = "Pass"
1+
conformant = "Partial"
22
output = """
33
generics_paramspec_semantics.py:26: error: Unexpected keyword argument "a" [call-arg]
44
generics_paramspec_semantics.py:26: error: Unexpected keyword argument "b" [call-arg]
@@ -11,7 +11,25 @@ generics_paramspec_semantics.py:127: error: Argument 1 to "expects_int_first" ha
1111
generics_paramspec_semantics.py:127: note: This is likely because "one" has named arguments: "x". Consider marking them positional-only
1212
generics_paramspec_semantics.py:132: error: Argument 1 to "expects_int_first" has incompatible type "def two(*, x: int) -> int"; expected "def (int, /, *, x: int) -> int" [arg-type]
1313
generics_paramspec_semantics.py:137: error: Argument 1 to "expects_int_first" has incompatible type "def three(**kwargs: int) -> int"; expected "def (int, /, **kwargs: int) -> int" [arg-type]
14+
generics_paramspec_semantics.py:151: error: Incompatible types in assignment (expression has type "ContravariantParamSpec[[int]]", variable has type "ContravariantParamSpec[[object]]") [assignment]
15+
generics_paramspec_semantics.py:155: error: Missing return statement [empty-body]
16+
generics_paramspec_semantics.py:158: error: Incompatible types in assignment (expression has type "CovariantParamSpec[[int]]", variable has type "CovariantParamSpec[[object]]") [assignment]
17+
generics_paramspec_semantics.py:161: error: The variance and bound arguments to ParamSpec do not have defined semantics yet [misc]
18+
generics_paramspec_semantics.py:165: error: Missing return statement [empty-body]
19+
generics_paramspec_semantics.py:169: error: Incompatible types in assignment (expression has type "ContravariantParamSpecOld[[int]]", variable has type "ContravariantParamSpecOld[[object]]") [assignment]
20+
generics_paramspec_semantics.py:171: error: The variance and bound arguments to ParamSpec do not have defined semantics yet [misc]
21+
generics_paramspec_semantics.py:175: error: Missing return statement [empty-body]
22+
generics_paramspec_semantics.py:178: error: Incompatible types in assignment (expression has type "ContravariantParamSpecOld[[int]]", variable has type "ContravariantParamSpecOld[[object]]") [assignment]
1423
"""
15-
conformance_automated = "Pass"
24+
conformance_automated = "Fail"
1625
errors_diff = """
26+
Line 159: Expected 1 errors
27+
Line 174: Expected 1 errors
28+
Line 179: Expected 1 errors
29+
Line 155: Unexpected errors ['generics_paramspec_semantics.py:155: error: Missing return statement [empty-body]']
30+
Line 158: Unexpected errors ['generics_paramspec_semantics.py:158: error: Incompatible types in assignment (expression has type "CovariantParamSpec[[int]]", variable has type "CovariantParamSpec[[object]]") [assignment]']
31+
Line 161: Unexpected errors ['generics_paramspec_semantics.py:161: error: The variance and bound arguments to ParamSpec do not have defined semantics yet [misc]']
32+
Line 171: Unexpected errors ['generics_paramspec_semantics.py:171: error: The variance and bound arguments to ParamSpec do not have defined semantics yet [misc]']
33+
Line 175: Unexpected errors ['generics_paramspec_semantics.py:175: error: Missing return statement [empty-body]']
34+
Line 178: Unexpected errors ['generics_paramspec_semantics.py:178: error: Incompatible types in assignment (expression has type "ContravariantParamSpecOld[[int]]", variable has type "ContravariantParamSpecOld[[object]]") [assignment]']
1735
"""

conformance/results/pyrefly/generics_paramspec_semantics.toml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1-
conformant = "Pass"
2-
conformance_automated = "Pass"
1+
conformant = "Partial"
2+
conformance_automated = "Fail"
33
errors_diff = """
4+
Line 151: Expected 1 errors
5+
Line 165: Expected 1 errors
6+
Line 174: Expected 1 errors
7+
Line 150: Unexpected errors ['`ContravariantParamSpec[[object]]` is not assignable to `ContravariantParamSpec[[int]]` [bad-assignment]']
8+
Line 161: Unexpected errors ['Unexpected keyword argument `contravariant` to ParamSpec [invalid-param-spec]']
9+
Line 168: Unexpected errors ['`ContravariantParamSpecOld[[object]]` is not assignable to `ContravariantParamSpecOld[[int]]` [bad-assignment]']
10+
Line 171: Unexpected errors ['Unexpected keyword argument `covariant` to ParamSpec [invalid-param-spec]']
11+
Line 178: Unexpected errors ['`ContravariantParamSpecOld[[int]]` is not assignable to `ContravariantParamSpecOld[[object]]` [bad-assignment]']
412
"""
513
output = """
614
ERROR generics_paramspec_semantics.py:26:4-5: Expected argument `a` to be positional [unexpected-keyword]
@@ -14,4 +22,12 @@ ERROR generics_paramspec_semantics.py:120:4-5: Argument `Literal[1]` is not assi
1422
ERROR generics_paramspec_semantics.py:127:1-19: Argument `(x: str) -> int` is not assignable to parameter `x` with type `(int, ParamSpec(@_)) -> int` in function `expects_int_first` [bad-argument-type]
1523
ERROR generics_paramspec_semantics.py:132:1-19: Argument `(*, x: int) -> int` is not assignable to parameter `x` with type `(int, ParamSpec(@_)) -> int` in function `expects_int_first` [bad-argument-type]
1624
ERROR generics_paramspec_semantics.py:137:1-19: Argument `(**kwargs: int) -> int` is not assignable to parameter `x` with type `(int, ParamSpec(@_)) -> int` in function `expects_int_first` [bad-argument-type]
25+
ERROR generics_paramspec_semantics.py:150:39-45: `ContravariantParamSpec[[object]]` is not assignable to `ContravariantParamSpec[[int]]` [bad-assignment]
26+
ERROR generics_paramspec_semantics.py:159:11-18: `CovariantParamSpec[[object]]` is not assignable to variable `out_int` with type `CovariantParamSpec[[int]]` [bad-assignment]
27+
ERROR generics_paramspec_semantics.py:161:24-42: Unexpected keyword argument `contravariant` to ParamSpec [invalid-param-spec]
28+
ERROR generics_paramspec_semantics.py:168:46-56: `ContravariantParamSpecOld[[object]]` is not assignable to `ContravariantParamSpecOld[[int]]` [bad-assignment]
29+
ERROR generics_paramspec_semantics.py:169:14-24: `ContravariantParamSpecOld[[int]]` is not assignable to variable `in_obj_old` with type `ContravariantParamSpecOld[[object]]` [bad-assignment]
30+
ERROR generics_paramspec_semantics.py:171:26-40: Unexpected keyword argument `covariant` to ParamSpec [invalid-param-spec]
31+
ERROR generics_paramspec_semantics.py:178:50-61: `ContravariantParamSpecOld[[int]]` is not assignable to `ContravariantParamSpecOld[[object]]` [bad-assignment]
32+
ERROR generics_paramspec_semantics.py:179:15-26: `ContravariantParamSpecOld[[object]]` is not assignable to variable `out_int_old` with type `ContravariantParamSpecOld[[int]]` [bad-assignment]
1733
"""

conformance/results/pyright/generics_paramspec_semantics.toml

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
conformant = "Pass"
1+
conformant = "Partial"
22
notes = """
33
Constraint solver doesn't find common type for two signatures captured by a single ParamSpec (allowed).
44
"""
@@ -30,7 +30,41 @@ generics_paramspec_semantics.py:132:2 - error: Argument of type "(*, x: int) ->
3030
generics_paramspec_semantics.py:137:2 - error: Argument of type "(**kwargs: int) -> int" cannot be assigned to parameter "x" of type "(int, **P@expects_int_first) -> int" in function "expects_int_first"
3131
  Type "(**kwargs: int) -> int" is not assignable to type "(int, **P@expects_int_first) -> int"
3232
    Function accepts too many positional parameters; expected 0 but received 1 (reportArgumentType)
33+
generics_paramspec_semantics.py:150:39 - error: Type "ContravariantParamSpec[(object)]" is not assignable to declared type "ContravariantParamSpec[(int)]"
34+
  "ContravariantParamSpec[(object)]" is not assignable to "ContravariantParamSpec[(int)]"
35+
    Type parameter "InP@ContravariantParamSpec" is invariant, but "(object)" is not the same as "(int)" (reportAssignmentType)
36+
generics_paramspec_semantics.py:151:10 - error: Type "ContravariantParamSpec[(int)]" is not assignable to declared type "ContravariantParamSpec[(object)]"
37+
  "ContravariantParamSpec[(int)]" is not assignable to "ContravariantParamSpec[(object)]"
38+
    Type parameter "InP@ContravariantParamSpec" is invariant, but "(int)" is not the same as "(object)" (reportAssignmentType)
39+
generics_paramspec_semantics.py:158:39 - error: Type "CovariantParamSpec[(int)]" is not assignable to declared type "CovariantParamSpec[(object)]"
40+
  "CovariantParamSpec[(int)]" is not assignable to "CovariantParamSpec[(object)]"
41+
    Type parameter "OutP@CovariantParamSpec" is invariant, but "(int)" is not the same as "(object)" (reportAssignmentType)
42+
generics_paramspec_semantics.py:159:11 - error: Type "CovariantParamSpec[(object)]" is not assignable to declared type "CovariantParamSpec[(int)]"
43+
  "CovariantParamSpec[(object)]" is not assignable to "CovariantParamSpec[(int)]"
44+
    Type parameter "OutP@CovariantParamSpec" is invariant, but "(object)" is not the same as "(int)" (reportAssignmentType)
45+
generics_paramspec_semantics.py:161:24 - error: "contravariant" is unknown parameter to ParamSpec (reportGeneralTypeIssues)
46+
generics_paramspec_semantics.py:168:46 - error: Type "ContravariantParamSpecOld[(object)]" is not assignable to declared type "ContravariantParamSpecOld[(int)]"
47+
  "ContravariantParamSpecOld[(object)]" is not assignable to "ContravariantParamSpecOld[(int)]"
48+
    Type parameter "InP@ContravariantParamSpecOld" is invariant, but "(object)" is not the same as "(int)" (reportAssignmentType)
49+
generics_paramspec_semantics.py:169:14 - error: Type "ContravariantParamSpecOld[(int)]" is not assignable to declared type "ContravariantParamSpecOld[(object)]"
50+
  "ContravariantParamSpecOld[(int)]" is not assignable to "ContravariantParamSpecOld[(object)]"
51+
    Type parameter "InP@ContravariantParamSpecOld" is invariant, but "(int)" is not the same as "(object)" (reportAssignmentType)
52+
generics_paramspec_semantics.py:171:26 - error: "covariant" is unknown parameter to ParamSpec (reportGeneralTypeIssues)
53+
generics_paramspec_semantics.py:178:50 - error: Type "ContravariantParamSpecOld[(int)]" is not assignable to declared type "ContravariantParamSpecOld[(object)]"
54+
  "ContravariantParamSpecOld[(int)]" is not assignable to "ContravariantParamSpecOld[(object)]"
55+
    Type parameter "InP@ContravariantParamSpecOld" is invariant, but "(int)" is not the same as "(object)" (reportAssignmentType)
56+
generics_paramspec_semantics.py:179:15 - error: Type "ContravariantParamSpecOld[(object)]" is not assignable to declared type "ContravariantParamSpecOld[(int)]"
57+
  "ContravariantParamSpecOld[(object)]" is not assignable to "ContravariantParamSpecOld[(int)]"
58+
    Type parameter "InP@ContravariantParamSpecOld" is invariant, but "(object)" is not the same as "(int)" (reportAssignmentType)
3359
"""
34-
conformance_automated = "Pass"
60+
conformance_automated = "Fail"
3561
errors_diff = """
62+
Line 165: Expected 1 errors
63+
Line 174: Expected 1 errors
64+
Line 150: Unexpected errors ['generics_paramspec_semantics.py:150:39 - error: Type "ContravariantParamSpec[(object)]" is not assignable to declared type "ContravariantParamSpec[(int)]"']
65+
Line 158: Unexpected errors ['generics_paramspec_semantics.py:158:39 - error: Type "CovariantParamSpec[(int)]" is not assignable to declared type "CovariantParamSpec[(object)]"']
66+
Line 161: Unexpected errors ['generics_paramspec_semantics.py:161:24 - error: "contravariant" is unknown parameter to ParamSpec (reportGeneralTypeIssues)']
67+
Line 168: Unexpected errors ['generics_paramspec_semantics.py:168:46 - error: Type "ContravariantParamSpecOld[(object)]" is not assignable to declared type "ContravariantParamSpecOld[(int)]"']
68+
Line 171: Unexpected errors ['generics_paramspec_semantics.py:171:26 - error: "covariant" is unknown parameter to ParamSpec (reportGeneralTypeIssues)']
69+
Line 178: Unexpected errors ['generics_paramspec_semantics.py:178:50 - error: Type "ContravariantParamSpecOld[(int)]" is not assignable to declared type "ContravariantParamSpecOld[(object)]"']
3670
"""

conformance/results/results.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -322,11 +322,11 @@ <h3>Python Type System Conformance Test Results</h3>
322322
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Incorrectly allows using `*args: P.args` and `**kwargs: P.kwargs` when `P` has not been put into scope by any other parameter annotation or enclosing scope.</p></span></div></th>
323323
</tr>
324324
<tr><th class="column col1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;generics_paramspec_semantics</th>
325-
<th class="column col2 conformant">Pass</th>
326-
<th class="column col2 conformant"><div class="hover-text">Pass*<span class="tooltip-text" id="bottom"><p>Constraint solver doesn't find common type for two signatures captured by a single ParamSpec (allowed).</p></span></div></th>
327-
<th class="column col2 conformant">Pass</th>
328-
<th class="column col2 conformant">Pass</th>
329-
<th class="column col2 conformant">Pass</th>
325+
<th class="column col2 partially-conformant">Partial</th>
326+
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Constraint solver doesn't find common type for two signatures captured by a single ParamSpec (allowed).</p></span></div></th>
327+
<th class="column col2 not-conformant">Unknown</th>
328+
<th class="column col2 partially-conformant">Partial</th>
329+
<th class="column col2 not-conformant">Unknown</th>
330330
</tr>
331331
<tr><th class="column col1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;generics_paramspec_specialization</th>
332332
<th class="column col2 conformant">Pass</th>

conformance/results/ty/generics_paramspec_semantics.toml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
1-
conformance_automated = "Pass"
1+
conformance_automated = "Fail"
22
errors_diff = """
3+
Line 151: Expected 1 errors
4+
Line 159: Expected 1 errors
5+
Line 169: Expected 1 errors
6+
Line 179: Expected 1 errors
7+
Line 155: Unexpected errors ['generics_paramspec_semantics.py:155:20: error[empty-body] Function always implicitly returns `None`, which is not assignable to return type `(**OutP@CovariantParamSpec) -> None`']
8+
Line 161: Unexpected errors ['generics_paramspec_semantics.py:161:7: error[invalid-paramspec] The variance and bound arguments for `ParamSpec` do not have defined semantics yet']
9+
Line 163: Unexpected errors ['generics_paramspec_semantics.py:163:33: error[invalid-argument-type] `ParamSpec` is not a valid argument to `Generic`']
10+
Line 164: Unexpected errors ['generics_paramspec_semantics.py:164:27: error[invalid-type-form] Variable of type `ParamSpecArgs` is not allowed in a type expression', 'generics_paramspec_semantics.py:164:47: error[invalid-type-form] Variable of type `ParamSpecKwargs` is not allowed in a type expression']
11+
Line 171: Unexpected errors ['generics_paramspec_semantics.py:171:8: error[invalid-paramspec] The variance and bound arguments for `ParamSpec` do not have defined semantics yet']
12+
Line 173: Unexpected errors ['generics_paramspec_semantics.py:173:29: error[invalid-argument-type] `ParamSpec` is not a valid argument to `Generic`']
13+
Line 175: Unexpected errors ['generics_paramspec_semantics.py:175:24: error[empty-body] Function always implicitly returns `None`, which is not assignable to return type `(...) -> Unknown`', 'generics_paramspec_semantics.py:175:33: error[invalid-type-form] Variable of type `ParamSpec` is not allowed in a type expression', 'generics_paramspec_semantics.py:175:33: error[invalid-type-form] The first argument to `Callable` must be either a list of types, ParamSpec, Concatenate, or `...`']
314
"""
415
output = """
516
generics_paramspec_semantics.py:26:4: error[positional-only-parameter-as-kwarg] Positional-only parameter 1 (`a`) passed as keyword argument
@@ -13,4 +24,19 @@ generics_paramspec_semantics.py:120:4: error[invalid-argument-type] Argument is
1324
generics_paramspec_semantics.py:127:1: error[invalid-argument-type] Argument to function `expects_int_first` is incorrect: Expected `(int, /, *args: Unknown, **kwargs: Unknown) -> int`, found `def one(x: str) -> int`
1425
generics_paramspec_semantics.py:132:1: error[invalid-argument-type] Argument to function `expects_int_first` is incorrect: Expected `(int, /, *args: Unknown, **kwargs: Unknown) -> int`, found `def two(*, x: int) -> int`
1526
generics_paramspec_semantics.py:137:1: error[invalid-argument-type] Argument to function `expects_int_first` is incorrect: Expected `(int, /, *args: Unknown, **kwargs: Unknown) -> int`, found `def three(**kwargs: int) -> int`
27+
generics_paramspec_semantics.py:155:20: error[empty-body] Function always implicitly returns `None`, which is not assignable to return type `(**OutP@CovariantParamSpec) -> None`
28+
generics_paramspec_semantics.py:161:7: error[invalid-paramspec] The variance and bound arguments for `ParamSpec` do not have defined semantics yet
29+
generics_paramspec_semantics.py:163:33: error[invalid-argument-type] `ParamSpec` is not a valid argument to `Generic`
30+
generics_paramspec_semantics.py:164:27: error[invalid-type-form] Variable of type `ParamSpecArgs` is not allowed in a type expression
31+
generics_paramspec_semantics.py:164:47: error[invalid-type-form] Variable of type `ParamSpecKwargs` is not allowed in a type expression
32+
generics_paramspec_semantics.py:165:24: error[empty-body] Function always implicitly returns `None`, which is not assignable to return type `(...) -> Unknown`
33+
generics_paramspec_semantics.py:165:33: error[invalid-type-form] Variable of type `ParamSpec` is not allowed in a type expression
34+
generics_paramspec_semantics.py:165:33: error[invalid-type-form] The first argument to `Callable` must be either a list of types, ParamSpec, Concatenate, or `...`
35+
generics_paramspec_semantics.py:171:8: error[invalid-paramspec] The variance and bound arguments for `ParamSpec` do not have defined semantics yet
36+
generics_paramspec_semantics.py:173:29: error[invalid-argument-type] `ParamSpec` is not a valid argument to `Generic`
37+
generics_paramspec_semantics.py:174:27: error[invalid-type-form] Variable of type `ParamSpecArgs` is not allowed in a type expression
38+
generics_paramspec_semantics.py:174:48: error[invalid-type-form] Variable of type `ParamSpecKwargs` is not allowed in a type expression
39+
generics_paramspec_semantics.py:175:24: error[empty-body] Function always implicitly returns `None`, which is not assignable to return type `(...) -> Unknown`
40+
generics_paramspec_semantics.py:175:33: error[invalid-type-form] Variable of type `ParamSpec` is not allowed in a type expression
41+
generics_paramspec_semantics.py:175:33: error[invalid-type-form] The first argument to `Callable` must be either a list of types, ParamSpec, Concatenate, or `...`
1642
"""

0 commit comments

Comments
 (0)