Skip to content

Commit b6411fa

Browse files
Add TypeForm (PEP 747) to the spec and conformance suite (#2183)
1 parent a8ec0a7 commit b6411fa

File tree

13 files changed

+606
-0
lines changed

13 files changed

+606
-0
lines changed

conformance/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ This project contains test cases for behaviors defined in the Python typing spec
1212

1313
* [concepts](https://typing.python.org/en/latest/spec/concepts.html)
1414
* [annotations](https://typing.python.org/en/latest/spec/annotations.html)
15+
* [typeforms](https://typing.python.org/en/latest/spec/type-forms.html)
1516
* [specialtypes](https://typing.python.org/en/latest/spec/special-types.html)
1617
* [generics](https://typing.python.org/en/latest/spec/generics.html)
1718
* [qualifiers](https://typing.python.org/en/latest/spec/qualifiers.html)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
conformant = "Partial"
2+
notes = """
3+
Does not support assigning Union and GenericAlias objects to their runtime types.
4+
"""
5+
conformance_automated = "Fail"
6+
errors_diff = """
7+
Line 46: Unexpected errors ['typeforms_typeform.py:46: error: Incompatible types in assignment (expression has type "UnionType | type[str]", variable has type "UnionType") [assignment]']
8+
Line 49: Unexpected errors ['typeforms_typeform.py:49: error: Incompatible types in assignment (expression has type "type[list[int]]", variable has type "GenericAlias") [assignment]']
9+
"""
10+
output = """
11+
typeforms_typeform.py:23: error: Incompatible types in assignment (expression has type "TypeForm[str | int]", variable has type "TypeForm[str | None]") [assignment]
12+
typeforms_typeform.py:24: error: Incompatible types in assignment (expression has type "TypeForm[list[str | None]]", variable has type "TypeForm[str | None]") [assignment]
13+
typeforms_typeform.py:46: error: Incompatible types in assignment (expression has type "UnionType | type[str]", variable has type "UnionType") [assignment]
14+
typeforms_typeform.py:49: error: Incompatible types in assignment (expression has type "type[list[int]]", variable has type "GenericAlias") [assignment]
15+
typeforms_typeform.py:59: error: Argument 1 to "func1" has incompatible type "str"; expected "TypeForm[Any]" [arg-type]
16+
typeforms_typeform.py:67: error: Incompatible types in assignment (expression has type "tuple[Never, ...]", variable has type "TypeForm[Any]") [assignment]
17+
typeforms_typeform.py:68: error: Incompatible types in assignment (expression has type "tuple[int, int]", variable has type "TypeForm[Any]") [assignment]
18+
typeforms_typeform.py:69: error: Incompatible types in assignment (expression has type "int", variable has type "TypeForm[Any]") [assignment]
19+
typeforms_typeform.py:70: error: Incompatible types in assignment (expression has type "<typing special form>", variable has type "TypeForm[Any]") [assignment]
20+
typeforms_typeform.py:71: error: Incompatible types in assignment (expression has type "<typing special form>", variable has type "TypeForm[Any]") [assignment]
21+
typeforms_typeform.py:72: error: Incompatible types in assignment (expression has type "<typing special form>", variable has type "TypeForm[Any]") [assignment]
22+
typeforms_typeform.py:73: error: Incompatible types in assignment (expression has type "<typing special form>", variable has type "TypeForm[Any]") [assignment]
23+
typeforms_typeform.py:74: error: Incompatible types in assignment (expression has type "<typing special form>", variable has type "TypeForm[Any]") [assignment]
24+
typeforms_typeform.py:75: error: Incompatible types in assignment (expression has type "str", variable has type "TypeForm[Any]") [assignment]
25+
typeforms_typeform.py:86: error: Invalid type comment or annotation [valid-type]
26+
typeforms_typeform.py:88: error: TypeForm argument is not a type [misc]
27+
typeforms_typeform.py:98: error: Incompatible types in assignment (expression has type "TypeForm[int]", variable has type "TypeForm[str]") [assignment]
28+
typeforms_typeform.py:108: error: Incompatible types in assignment (expression has type "type[int]", variable has type "TypeForm[str]") [assignment]
29+
"""
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
conformant = "Unsupported"
2+
conformance_automated = "Fail"
3+
errors_diff = """
4+
Line 59: Expected 1 errors
5+
Line 15: Unexpected errors ['Expected a type form, got instance of `object` [not-a-type]']
6+
Line 16: Unexpected errors ['Expected a type form, got instance of `object` [not-a-type]']
7+
Line 17: Unexpected errors ['Expected a type form, got instance of `object` [not-a-type]']
8+
Line 18: Unexpected errors ['Expected a type form, got instance of `object` [not-a-type]']
9+
Line 19: Unexpected errors ['Expected a type form, got instance of `object` [not-a-type]']
10+
Line 20: Unexpected errors ['Expected a type form, got instance of `object` [not-a-type]']
11+
Line 21: Unexpected errors ['Expected a type form, got instance of `object` [not-a-type]']
12+
Line 29: Unexpected errors ['Expected a type form, got instance of `object` [not-a-type]']
13+
Line 30: Unexpected errors ['Expected a type form, got instance of `object` [not-a-type]']
14+
Line 31: Unexpected errors ['Expected a type form, got instance of `object` [not-a-type]']
15+
Line 32: Unexpected errors ['Expected a type form, got instance of `object` [not-a-type]']
16+
Line 40: Unexpected errors ['Expected a type form, got instance of `_SpecialForm` [not-a-type]']
17+
Line 41: Unexpected errors ['Expected a type form, got instance of `object` [not-a-type]']
18+
Line 46: Unexpected errors ['`type[str | None]` is not assignable to `UnionType` [bad-assignment]']
19+
Line 47: Unexpected errors ['Expected a type form, got instance of `object` [not-a-type]']
20+
Line 49: Unexpected errors ['`type[list[int]]` is not assignable to `GenericAlias` [bad-assignment]', 'Expected `v2_actual` to be a type alias, got `GenericAlias` [invalid-type-alias]']
21+
Line 50: Unexpected errors ['Expected a type form, got instance of `_SpecialForm` [not-a-type]']
22+
Line 52: Unexpected errors ['Expected a type form, got instance of `object` [not-a-type]']
23+
Line 53: Unexpected errors ['Expected a type form, got instance of `object` [not-a-type]']
24+
Line 80: Unexpected errors ['Expected a callable, got `_SpecialForm` [not-callable]']
25+
Line 81: Unexpected errors ['Expected a type form, got instance of `object` [not-a-type]']
26+
Line 83: Unexpected errors ['Expected a callable, got `_SpecialForm` [not-callable]']
27+
Line 84: Unexpected errors ['Expected a type form, got instance of `object` [not-a-type]']
28+
Line 93: Unexpected errors ['Expected a type form, got instance of `object` [not-a-type]']
29+
Line 97: Unexpected errors ['Expected a type form, got instance of `object` [not-a-type]']
30+
Line 107: Unexpected errors ['Expected a type form, got instance of `object` [not-a-type]']
31+
"""
32+
output = """
33+
ERROR typeforms_typeform.py:15:6-26: Expected a type form, got instance of `object` [not-a-type]
34+
ERROR typeforms_typeform.py:16:6-26: Expected a type form, got instance of `object` [not-a-type]
35+
ERROR typeforms_typeform.py:17:6-26: Expected a type form, got instance of `object` [not-a-type]
36+
ERROR typeforms_typeform.py:18:6-26: Expected a type form, got instance of `object` [not-a-type]
37+
ERROR typeforms_typeform.py:19:6-26: Expected a type form, got instance of `object` [not-a-type]
38+
ERROR typeforms_typeform.py:20:6-26: Expected a type form, got instance of `object` [not-a-type]
39+
ERROR typeforms_typeform.py:21:6-26: Expected a type form, got instance of `object` [not-a-type]
40+
ERROR typeforms_typeform.py:23:7-27: Expected a type form, got instance of `object` [not-a-type]
41+
ERROR typeforms_typeform.py:24:7-27: Expected a type form, got instance of `object` [not-a-type]
42+
ERROR typeforms_typeform.py:29:8-21: Expected a type form, got instance of `object` [not-a-type]
43+
ERROR typeforms_typeform.py:30:8-21: Expected a type form, got instance of `object` [not-a-type]
44+
ERROR typeforms_typeform.py:31:20-33: Expected a type form, got instance of `object` [not-a-type]
45+
ERROR typeforms_typeform.py:32:20-33: Expected a type form, got instance of `object` [not-a-type]
46+
ERROR typeforms_typeform.py:40:14-22: Expected a type form, got instance of `_SpecialForm` [not-a-type]
47+
ERROR typeforms_typeform.py:41:20-33: Expected a type form, got instance of `object` [not-a-type]
48+
ERROR typeforms_typeform.py:46:30-40: `type[str | None]` is not assignable to `UnionType` [bad-assignment]
49+
ERROR typeforms_typeform.py:47:15-35: Expected a type form, got instance of `object` [not-a-type]
50+
ERROR typeforms_typeform.py:49:33-42: `type[list[int]]` is not assignable to `GenericAlias` [bad-assignment]
51+
ERROR typeforms_typeform.py:49:33-42: Expected `v2_actual` to be a type alias, got `GenericAlias` [invalid-type-alias]
52+
ERROR typeforms_typeform.py:50:15-23: Expected a type form, got instance of `_SpecialForm` [not-a-type]
53+
ERROR typeforms_typeform.py:52:5-24: Expected a type form, got instance of `object` [not-a-type]
54+
ERROR typeforms_typeform.py:53:5-23: Expected a type form, got instance of `object` [not-a-type]
55+
ERROR typeforms_typeform.py:67:7-15: Expected a type form, got instance of `_SpecialForm` [not-a-type]
56+
ERROR typeforms_typeform.py:68:7-15: Expected a type form, got instance of `_SpecialForm` [not-a-type]
57+
ERROR typeforms_typeform.py:69:7-15: Expected a type form, got instance of `_SpecialForm` [not-a-type]
58+
ERROR typeforms_typeform.py:70:7-15: Expected a type form, got instance of `_SpecialForm` [not-a-type]
59+
ERROR typeforms_typeform.py:70:18-22: `Self` must appear within a class [invalid-annotation]
60+
ERROR typeforms_typeform.py:71:7-15: Expected a type form, got instance of `_SpecialForm` [not-a-type]
61+
ERROR typeforms_typeform.py:71:18-31: `ClassVar` is not allowed in this context [invalid-annotation]
62+
ERROR typeforms_typeform.py:72:7-15: Expected a type form, got instance of `_SpecialForm` [not-a-type]
63+
ERROR typeforms_typeform.py:72:18-28: `Final` is not allowed in this context [invalid-annotation]
64+
ERROR typeforms_typeform.py:73:7-15: Expected a type form, got instance of `_SpecialForm` [not-a-type]
65+
ERROR typeforms_typeform.py:74:7-15: Expected a type form, got instance of `_SpecialForm` [not-a-type]
66+
ERROR typeforms_typeform.py:75:7-15: Expected a type form, got instance of `_SpecialForm` [not-a-type]
67+
ERROR typeforms_typeform.py:80:6-14: Expected a callable, got `_SpecialForm` [not-callable]
68+
ERROR typeforms_typeform.py:81:17-37: Expected a type form, got instance of `object` [not-a-type]
69+
ERROR typeforms_typeform.py:83:6-14: Expected a callable, got `_SpecialForm` [not-callable]
70+
ERROR typeforms_typeform.py:84:17-36: Expected a type form, got instance of `object` [not-a-type]
71+
ERROR typeforms_typeform.py:86:6-14: Expected a callable, got `_SpecialForm` [not-callable]
72+
ERROR typeforms_typeform.py:88:6-14: Expected a callable, got `_SpecialForm` [not-callable]
73+
ERROR typeforms_typeform.py:93:24-37: Expected a type form, got instance of `object` [not-a-type]
74+
ERROR typeforms_typeform.py:97:5-24: Expected a type form, got instance of `object` [not-a-type]
75+
ERROR typeforms_typeform.py:98:5-18: Expected a type form, got instance of `object` [not-a-type]
76+
ERROR typeforms_typeform.py:107:5-24: Expected a type form, got instance of `object` [not-a-type]
77+
ERROR typeforms_typeform.py:108:5-18: Expected a type form, got instance of `object` [not-a-type]
78+
"""
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
conformant = "Unsupported"
2+
conformance_automated = "Fail"
3+
errors_diff = """
4+
Line 70: Expected 1 errors
5+
Line 71: Expected 1 errors
6+
Line 72: Expected 1 errors
7+
Line 74: Expected 1 errors
8+
Line 15: Unexpected errors ['typeforms_typeform.py:15:29 - error: Type "UnionType" is not assignable to declared type "TypeForm[str | None]"']
9+
Line 17: Unexpected errors ['typeforms_typeform.py:17:29 - error: Type "None" is not assignable to declared type "TypeForm[str | None]"']
10+
Line 19: Unexpected errors ['typeforms_typeform.py:19:29 - error: Type "UnionType" is not assignable to declared type "TypeForm[str | None]"']
11+
Line 20: Unexpected errors ['typeforms_typeform.py:20:29 - error: Type "Literal[\\'str | None\\']" is not assignable to declared type "TypeForm[str | None]"']
12+
Line 21: Unexpected errors ['typeforms_typeform.py:21:29 - error: Type "type[Any]" is not assignable to declared type "TypeForm[str | None]"']
13+
Line 29: Unexpected errors ['typeforms_typeform.py:29:24 - error: Type "UnionType" is not assignable to declared type "TypeForm[Any]"']
14+
Line 32: Unexpected errors ['typeforms_typeform.py:32:13 - error: "assert_type" mismatch: expected "TypeForm[str]" but received "type[str]" (reportAssertTypeFailure)']
15+
Line 47: Unexpected errors ['typeforms_typeform.py:47:38 - error: Type "UnionType" is not assignable to declared type "TypeForm[str | None]"']
16+
Line 49: Unexpected errors ['typeforms_typeform.py:49:33 - error: Type "type[list[int]]" is not assignable to declared type "GenericAlias"']
17+
Line 52: Unexpected errors ['typeforms_typeform.py:52:27 - error: Type "Annotated" is not assignable to declared type "TypeForm[int | str]"']
18+
Line 53: Unexpected errors ['typeforms_typeform.py:53:26 - error: Type "Literal[\\'set[str]\\']" is not assignable to declared type "TypeForm[set[str]]"']
19+
Line 58: Unexpected errors ['typeforms_typeform.py:58:7 - error: Argument of type "Literal[\\'int\\']" cannot be assigned to parameter "x" of type "TypeForm[Unknown]" in function "func1"']
20+
Line 81: Unexpected errors ['typeforms_typeform.py:81:13 - error: "assert_type" mismatch: expected "TypeForm[str | None]" but received "UnionType" (reportAssertTypeFailure)']
21+
Line 84: Unexpected errors ['typeforms_typeform.py:84:13 - error: "assert_type" mismatch: expected "TypeForm[list[int]]" but received "type[list[int]]" (reportAssertTypeFailure)']
22+
"""
23+
output = """
24+
typeforms_typeform.py:15:29 - error: Type "UnionType" is not assignable to declared type "TypeForm[str | None]"
25+
  "UnionType" is not assignable to "TypeForm[str | None]" (reportAssignmentType)
26+
typeforms_typeform.py:17:29 - error: Type "None" is not assignable to declared type "TypeForm[str | None]"
27+
  "None" is not assignable to "TypeForm[str | None]" (reportAssignmentType)
28+
typeforms_typeform.py:19:29 - error: Type "UnionType" is not assignable to declared type "TypeForm[str | None]"
29+
  "UnionType" is not assignable to "TypeForm[str | None]" (reportAssignmentType)
30+
typeforms_typeform.py:20:29 - error: Type "Literal['str | None']" is not assignable to declared type "TypeForm[str | None]"
31+
  "Literal['str | None']" is not assignable to "TypeForm[str | None]" (reportAssignmentType)
32+
typeforms_typeform.py:21:29 - error: Type "type[Any]" is not assignable to declared type "TypeForm[str | None]"
33+
  Type "Any" is not assignable to type "str | None"
34+
    "Any" is not assignable to "str"
35+
    "Any" is not assignable to "None" (reportAssignmentType)
36+
typeforms_typeform.py:23:30 - error: Type "UnionType" is not assignable to declared type "TypeForm[str | None]"
37+
  "UnionType" is not assignable to "TypeForm[str | None]" (reportAssignmentType)
38+
typeforms_typeform.py:24:30 - error: Type "type[list[str | None]]" is not assignable to declared type "TypeForm[str | None]"
39+
  Type "list[str | None]" is not assignable to type "str | None"
40+
    "list[str | None]" is not assignable to "str"
41+
    "list[str | None]" is not assignable to "None" (reportAssignmentType)
42+
typeforms_typeform.py:29:24 - error: Type "UnionType" is not assignable to declared type "TypeForm[Any]"
43+
  "UnionType" is not assignable to "TypeForm[Any]" (reportAssignmentType)
44+
typeforms_typeform.py:32:13 - error: "assert_type" mismatch: expected "TypeForm[str]" but received "type[str]" (reportAssertTypeFailure)
45+
typeforms_typeform.py:47:38 - error: Type "UnionType" is not assignable to declared type "TypeForm[str | None]"
46+
  "UnionType" is not assignable to "TypeForm[str | None]" (reportAssignmentType)
47+
typeforms_typeform.py:49:33 - error: Type "type[list[int]]" is not assignable to declared type "GenericAlias"
48+
  Type "type[list[int]]" is not assignable to type "GenericAlias" (reportAssignmentType)
49+
typeforms_typeform.py:52:27 - error: Type "Annotated" is not assignable to declared type "TypeForm[int | str]"
50+
  "Annotated" is not assignable to "TypeForm[int | str]" (reportAssignmentType)
51+
typeforms_typeform.py:53:26 - error: Type "Literal['set[str]']" is not assignable to declared type "TypeForm[set[str]]"
52+
  "Literal['set[str]']" is not assignable to "TypeForm[set[str]]" (reportAssignmentType)
53+
typeforms_typeform.py:58:7 - error: Argument of type "Literal['int']" cannot be assigned to parameter "x" of type "TypeForm[Unknown]" in function "func1"
54+
  "Literal['int']" is not assignable to "TypeForm[Unknown]" (reportArgumentType)
55+
typeforms_typeform.py:59:7 - error: Argument of type "Literal['not a type']" cannot be assigned to parameter "x" of type "TypeForm[Unknown]" in function "func1"
56+
  "Literal['not a type']" is not assignable to "TypeForm[Unknown]" (reportArgumentType)
57+
typeforms_typeform.py:67:18 - error: Type "tuple[()]" is not assignable to declared type "TypeForm[Unknown]"
58+
  "tuple[()]" is not assignable to "TypeForm[Unknown]" (reportAssignmentType)
59+
typeforms_typeform.py:68:18 - error: Type "tuple[Literal[1], Literal[2]]" is not assignable to declared type "TypeForm[Unknown]"
60+
  "tuple[Literal[1], Literal[2]]" is not assignable to "TypeForm[Unknown]" (reportAssignmentType)
61+
typeforms_typeform.py:69:18 - error: Type "Literal[1]" is not assignable to declared type "TypeForm[Unknown]"
62+
  "Literal[1]" is not assignable to "TypeForm[Unknown]" (reportAssignmentType)
63+
typeforms_typeform.py:73:25 - error: Type variable "Ts" has no meaning in this context (reportGeneralTypeIssues)
64+
typeforms_typeform.py:75:18 - error: Type "Literal['int + str']" is not assignable to declared type "TypeForm[Unknown]"
65+
  "Literal['int + str']" is not assignable to "TypeForm[Unknown]" (reportAssignmentType)
66+
typeforms_typeform.py:81:13 - error: "assert_type" mismatch: expected "TypeForm[str | None]" but received "UnionType" (reportAssertTypeFailure)
67+
typeforms_typeform.py:84:13 - error: "assert_type" mismatch: expected "TypeForm[list[int]]" but received "type[list[int]]" (reportAssertTypeFailure)
68+
typeforms_typeform.py:86:16 - error: type() call should not be used in type expression
69+
  Use type[T] instead (reportInvalidTypeForm)
70+
typeforms_typeform.py:86:16 - error: Call expression not allowed in type expression (reportInvalidTypeForm)
71+
typeforms_typeform.py:88:15 - error: type() call should not be used in type expression
72+
  Use type[T] instead (reportInvalidTypeForm)
73+
typeforms_typeform.py:88:15 - error: Call expression not allowed in type expression (reportInvalidTypeForm)
74+
typeforms_typeform.py:98:21 - error: Type "TypeForm[int]" is not assignable to declared type "TypeForm[str]"
75+
  "TypeForm[int]" is not assignable to "TypeForm[str]"
76+
    Type parameter "T@TypeForm" is covariant, but "int" is not a subtype of "str"
77+
      "int" is not assignable to "str" (reportAssignmentType)
78+
typeforms_typeform.py:108:21 - error: Type "type[int]" is not assignable to declared type "TypeForm[str]"
79+
  "int" is not assignable to "str" (reportAssignmentType)
80+
"""

conformance/results/results.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,16 @@ <h3>Python Type System Conformance Test Results</h3>
222222
<th class="column col2 conformant">Pass</th>
223223
</tr>
224224
<tr><th class="column" colspan="6">
225+
<a class="test_group" href="https://typing.readthedocs.io/en/latest/spec/type-forms.html">Type forms</a>
226+
</th></tr>
227+
<tr><th class="column col1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;typeforms_typeform</th>
228+
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Does not support assigning Union and GenericAlias objects to their runtime types.</p></span></div></th>
229+
<th class="column col2 not-conformant">Unsupported</th>
230+
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>TypeForm[Any] is not considered equivalent to itself.</p></span></div></th>
231+
<th class="column col2 not-conformant">Unsupported</th>
232+
<th class="column col2 not-conformant">Unsupported</th>
233+
</tr>
234+
<tr><th class="column" colspan="6">
225235
<a class="test_group" href="https://typing.readthedocs.io/en/latest/spec/special-types.html">Special types in annotations</a>
226236
</th></tr>
227237
<tr><th class="column col1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;specialtypes_any</th>

0 commit comments

Comments
 (0)