Skip to content

Commit b57e1ff

Browse files
JelleZijlstrabrianschubertsinon
authored
Add spec and tests for PEP 728 (#2068)
I mostly copied the spec from PEP 728, with light editing to remove references to "this PEP" and fix links. In a followup I plan to reorganize the TypedDict spec. The conformance tests primarily derive from the examples in the PEP. Co-authored-by: Brian Schubert <[email protected]> Co-authored-by: Rob Hand <[email protected]>
1 parent d2f9b08 commit b57e1ff

File tree

8 files changed

+1397
-4
lines changed

8 files changed

+1397
-4
lines changed

conformance/results/mypy/typeddicts_extra_items.toml

Lines changed: 143 additions & 0 deletions
Large diffs are not rendered by default.

conformance/results/pyre/typeddicts_extra_items.toml

Lines changed: 139 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
conformant = "Pass"
2+
conformance_automated = "Pass"
3+
errors_diff = """
4+
"""
5+
output = """
6+
typeddicts_extra_items.py:15:45 - error: Type "dict[str, str | int]" is not assignable to declared type "Movie"
7+
  "Literal[1982]" is not assignable to "bool" (reportAssignmentType)
8+
typeddicts_extra_items.py:22:55 - error: Type "dict[str, str | int]" is not assignable to declared type "MovieFunctional"
9+
  "Literal[1982]" is not assignable to "bool" (reportAssignmentType)
10+
typeddicts_extra_items.py:39:54 - error: Type "dict[str, str | None]" is not assignable to declared type "InheritedMovie"
11+
  "None" is not assignable to "int" (reportAssignmentType)
12+
typeddicts_extra_items.py:49:35 - error: Expected "closed" parameter to have a value of True or False (reportGeneralTypeIssues)
13+
typeddicts_extra_items.py:67:7 - error: Base class "ClosedBase" is a TypedDict that limits the type of extra items to type "Never"
14+
  Cannot add item "age" (reportIncompatibleVariableOverride)
15+
typeddicts_extra_items.py:73:7 - error: Base class "ExtraItemsBase" is a TypedDict that limits the type of extra items to type "int"
16+
  Cannot add item "age" because it must be NotRequired (reportIncompatibleVariableOverride)
17+
typeddicts_extra_items.py:91:7 - error: Base class "MovieA" is a TypedDict that limits the type of extra items to type "Never"
18+
  Cannot add item "age" (reportIncompatibleVariableOverride)
19+
typeddicts_extra_items.py:94:7 - error: Base class "MovieB" is a TypedDict that limits the type of extra items to type "Never"
20+
  Cannot add item "age" (reportIncompatibleVariableOverride)
21+
typeddicts_extra_items.py:111:50 - error: "Required" is not allowed in this context (reportInvalidTypeForm)
22+
typeddicts_extra_items.py:114:57 - error: "NotRequired" is not allowed in this context (reportInvalidTypeForm)
23+
typeddicts_extra_items.py:125:9 - error: Could not delete item in TypedDict
24+
  "name" is a required key and cannot be deleted (reportGeneralTypeIssues)
25+
typeddicts_extra_items.py:140:48 - error: No parameter named "year" (reportCallIssue)
26+
typeddicts_extra_items.py:171:7 - error: Base class "Parent" is a TypedDict that limits the type of extra items to type "int | None"
27+
  Cannot add item "extra_items" with type "int" (reportIncompatibleVariableOverride)
28+
typeddicts_extra_items.py:181:7 - error: Base class "MovieBase2" is a TypedDict that limits the type of extra items to type "int | None"
29+
  Cannot add item "year" because it must be NotRequired (reportIncompatibleVariableOverride)
30+
typeddicts_extra_items.py:184:7 - error: Base class "MovieBase2" is a TypedDict that limits the type of extra items to type "int | None"
31+
  Cannot add item "year" with type "int" (reportIncompatibleVariableOverride)
32+
typeddicts_extra_items.py:206:22 - error: Type "MovieDetails" is not assignable to declared type "MovieBase2"
33+
  Type of "year" is incompatible with type of "extra_items" in "MovieBase2"
34+
    Type "int" is not assignable to type "int | None"
35+
      "int" is not assignable to "None" (reportAssignmentType)
36+
typeddicts_extra_items.py:213:22 - error: Type "MovieWithYear2" is not assignable to declared type "MovieBase2"
37+
  "year" is not required in "MovieBase2" (reportAssignmentType)
38+
typeddicts_extra_items.py:233:19 - error: Type "MovieDetails5" is not assignable to declared type "MovieSI"
39+
  Type of "actors" is incompatible with type of "extra_items" in "MovieSI"
40+
    Type "list[str]" is not assignable to type "str | int"
41+
      "list[str]" is not assignable to "str"
42+
      "list[str]" is not assignable to "int" (reportAssignmentType)
43+
typeddicts_extra_items.py:247:13 - error: Type "MovieExtraStr" is not assignable to declared type "MovieExtraInt"
44+
  Type of "extra_items" is incompatible with type of "extra_items" in "MovieExtraStr"
45+
    "str" is not assignable to "int" (reportAssignmentType)
46+
typeddicts_extra_items.py:248:13 - error: Type "MovieExtraInt" is not assignable to declared type "MovieExtraStr"
47+
  Type of "extra_items" is incompatible with type of "extra_items" in "MovieExtraInt"
48+
    "int" is not assignable to "str" (reportAssignmentType)
49+
typeddicts_extra_items.py:259:14 - error: Type "MovieNotClosed" is not assignable to declared type "MovieExtraInt"
50+
  Type of "extra_items" is incompatible with type of "extra_items" in "MovieNotClosed"
51+
    "object" is not assignable to "int" (reportAssignmentType)
52+
typeddicts_extra_items.py:269:1 - error: No overloads for "__init__" match the provided arguments
53+
  Argument types: (Literal['No Country for Old Men'], Literal[2007]) (reportCallIssue)
54+
typeddicts_extra_items.py:276:52 - error: Argument of type "Literal['English']" cannot be assigned to parameter "language" of type "int" in function "__init__"
55+
  "Literal['English']" is not assignable to "int" (reportArgumentType)
56+
typeddicts_extra_items.py:284:1 - error: No overloads for "__init__" match the provided arguments
57+
  Argument types: (Literal['No Country for Old Men'], Literal[2007]) (reportCallIssue)
58+
typeddicts_extra_items.py:294:34 - error: Type "MovieExtraInt" is not assignable to declared type "Mapping[str, int]"
59+
  "Mapping[str, str | int]" is not assignable to "Mapping[str, int]"
60+
    Type parameter "_VT_co@Mapping" is covariant, but "str | int" is not a subtype of "int"
61+
      Type "str | int" is not assignable to type "int"
62+
        "str" is not assignable to "int" (reportAssignmentType)
63+
typeddicts_extra_items.py:343:25 - error: Type "dict[str, int]" is not assignable to declared type "IntDict"
64+
  "dict[str, int]" is not assignable to "IntDict" (reportAssignmentType)
65+
"""

conformance/results/results.html

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,13 @@ <h3>Python Type System Conformance Test Results</h3>
162162
<div class='tc-time'>2.0sec</div>
163163
</th>
164164
<th class='tc-header'><div class='tc-name'>pyright 1.1.403</div>
165-
<div class='tc-time'>1.8sec</div>
165+
<div class='tc-time'>1.3sec</div>
166166
</th>
167167
<th class='tc-header'><div class='tc-name'>pyre 0.9.25</div>
168-
<div class='tc-time'>10.3sec</div>
168+
<div class='tc-time'>10.2sec</div>
169169
</th>
170170
<th class='tc-header'><div class='tc-name'>zuban 0.0.19</div>
171-
<div class='tc-time'>0.35sec</div>
171+
<div class='tc-time'>0.32sec</div>
172172
</th>
173173
</tr>
174174
<tr><th class="column" colspan="5">
@@ -819,6 +819,12 @@ <h3>Python Type System Conformance Test Results</h3>
819819
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Does not reject methods within TypedDict class.</p><p>Does not report when metaclass is provided.</p><p>Does not report when other keyword argument is provided.</p><p>Does not support generic TypedDict class.</p></span></div></th>
820820
<th class="column col2 conformant">Pass</th>
821821
</tr>
822+
<tr><th class="column col1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;typeddicts_extra_items</th>
823+
<th class="column col2 not-conformant"><div class="hover-text">Unsupported<span class="tooltip-text" id="bottom"><p>Not supported.</p></span></div></th>
824+
<th class="column col2 conformant">Pass</th>
825+
<th class="column col2 not-conformant"><div class="hover-text">Unsupported<span class="tooltip-text" id="bottom"><p>Not supported.</p></span></div></th>
826+
<th class="column col2 not-conformant"><div class="hover-text">Unsupported<span class="tooltip-text" id="bottom"><p>Not supported.</p></span></div></th>
827+
</tr>
822828
<tr><th class="column col1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;typeddicts_final</th>
823829
<th class="column col2 conformant">Pass</th>
824830
<th class="column col2 conformant">Pass</th>

0 commit comments

Comments
 (0)