Skip to content

Commit 9dd5297

Browse files
committed
Merge remote-tracking branch 'upstream/main' into intfloat
2 parents a442bfe + 3fc17d1 commit 9dd5297

File tree

537 files changed

+8895
-9062
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

537 files changed

+8895
-9062
lines changed

.github/ISSUE_TEMPLATE/documentation-issue.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
name: Documentation issue
3-
about: Report a problem or suggest changes for the documentation at https://typing.readthedocs.io/
3+
about: Report a problem or suggest changes for the documentation at https://typing.python.org/
44
title: ''
55
labels: 'topic: documentation'
66
assignees: ''

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.5.0
3+
rev: v4.6.0
44
hooks:
55
- id: trailing-whitespace
66
exclude: conformance/results/.*/.*\.toml

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## Documentation and Support
44

55
The documentation for Python's static typing can be found at
6-
[typing.readthedocs.io](https://typing.readthedocs.io/). You can get
6+
[typing.python.org](https://typing.python.org/). You can get
77
help in our [support forum](https://github.com/python/typing/discussions).
88

99
Improvements to the type system should be discussed on
@@ -20,10 +20,10 @@ For conversations that are more suitable to a chat platform, you can use one of
2020

2121
This GitHub repository is used for several things:
2222

23-
- The documentation at [typing.readthedocs.io](https://typing.readthedocs.io/)
23+
- The documentation at [typing.python.org](https://typing.python.org/)
2424
is maintained in the [docs directory](./docs). This includes the
25-
[specification](https://typing.readthedocs.io/en/latest/spec/index.html) for the
26-
type system. See especially [the update procedure](https://typing.readthedocs.io/en/latest/spec/meta.html)
25+
[specification](https://typing.python.org/en/latest/spec/index.html) for the
26+
type system. See especially [the update procedure](https://typing.python.org/en/latest/spec/meta.html)
2727
for the spec.
2828

2929
- A [discussion forum](https://github.com/python/typing/discussions) for typing-related user

conformance/README.md

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,34 @@
22

33
## Motivation
44

5-
[PEP 729](https://peps.python.org/pep-0729/) provides a structured and documented way to specify and evolve the Python type system. In support of this effort, an official [Python typing spec](https://github.com/python/typing/tree/main/docs/spec) has been drafted. This spec consolidates details from various historical typing-related PEPs. The spec will be modified over time to clarify unspecified and under-specified parts of the type system. It will also be extended to cover new features of the type system.
5+
[PEP 729](https://peps.python.org/pep-0729/) provides a structured and documented way to specify and evolve the Python type system. In support of this effort, an official [Python typing spec](https://typing.python.org/en/latest/spec/) has been drafted. This spec consolidates details from various historical typing-related PEPs. The spec will be modified over time to clarify unspecified and under-specified parts of the type system. It will also be extended to cover new features of the type system.
66

77
Accompanying the typing specification is this conformance test suite which validates the behavior of static type checkers against the specification.
88

99
## Structure & Name
1010

1111
This project contains test cases for behaviors defined in the Python typing spec. Tests are structured and grouped in accordance with the specification's chapter headings.
1212

13-
* [concepts](https://typing.readthedocs.io/en/latest/spec/concepts.html)
14-
* [annotations](https://typing.readthedocs.io/en/latest/spec/annotations.html)
15-
* [specialtypes](https://typing.readthedocs.io/en/latest/spec/special-types.html)
16-
* [generics](https://typing.readthedocs.io/en/latest/spec/generics.html)
17-
* [qualifiers](https://typing.readthedocs.io/en/latest/spec/qualifiers.html)
18-
* [classes](https://typing.readthedocs.io/en/latest/spec/class-compat.html)
19-
* [aliases](https://typing.readthedocs.io/en/latest/spec/aliases.html)
20-
* [literals](https://typing.readthedocs.io/en/latest/spec/literal.html)
21-
* [protocols](https://typing.readthedocs.io/en/latest/spec/protocol.html)
22-
* [callables](https://typing.readthedocs.io/en/latest/spec/callables.html)
23-
* [constructors](https://typing.readthedocs.io/en/latest/spec/constructors.html)
24-
* [overloads](https://typing.readthedocs.io/en/latest/spec/overload.html)
25-
* [dataclasses](https://typing.readthedocs.io/en/latest/spec/dataclasses.html)
26-
* [typeddicts](https://typing.readthedocs.io/en/latest/spec/typeddict.html)
27-
* [tuples](https://typing.readthedocs.io/en/latest/spec/tuples.html)
28-
* [namedtuples](https://typing.readthedocs.io/en/latest/spec/namedtuples.html)
29-
* [narrowing](https://typing.readthedocs.io/en/latest/spec/narrowing.html)
30-
* [directives](https://typing.readthedocs.io/en/latest/spec/directives.html)
31-
* [distribution](https://typing.readthedocs.io/en/latest/spec/distributing.html)
32-
* [historical](https://typing.readthedocs.io/en/latest/spec/historical.html)
13+
* [concepts](https://typing.python.org/en/latest/spec/concepts.html)
14+
* [annotations](https://typing.python.org/en/latest/spec/annotations.html)
15+
* [specialtypes](https://typing.python.org/en/latest/spec/special-types.html)
16+
* [generics](https://typing.python.org/en/latest/spec/generics.html)
17+
* [qualifiers](https://typing.python.org/en/latest/spec/qualifiers.html)
18+
* [classes](https://typing.python.org/en/latest/spec/class-compat.html)
19+
* [aliases](https://typing.python.org/en/latest/spec/aliases.html)
20+
* [literals](https://typing.python.org/en/latest/spec/literal.html)
21+
* [protocols](https://typing.python.org/en/latest/spec/protocol.html)
22+
* [callables](https://typing.python.org/en/latest/spec/callables.html)
23+
* [constructors](https://typing.python.org/en/latest/spec/constructors.html)
24+
* [overloads](https://typing.python.org/en/latest/spec/overload.html)
25+
* [dataclasses](https://typing.python.org/en/latest/spec/dataclasses.html)
26+
* [typeddicts](https://typing.python.org/en/latest/spec/typeddict.html)
27+
* [tuples](https://typing.python.org/en/latest/spec/tuples.html)
28+
* [namedtuples](https://typing.python.org/en/latest/spec/namedtuples.html)
29+
* [narrowing](https://typing.python.org/en/latest/spec/narrowing.html)
30+
* [directives](https://typing.python.org/en/latest/spec/directives.html)
31+
* [distribution](https://typing.python.org/en/latest/spec/distributing.html)
32+
* [historical](https://typing.python.org/en/latest/spec/historical.html)
3333

3434
A test file is a ".py" file. The file name should start with one of the above names followed by a description of the test (with words separated by underscores). For example, `generics_paramspec_basic_usage.py` would contain the basic usage tests for `ParamSpec`. Each test file can contain multiple individual unit tests, but these tests should be related to each other. If the number of unit tests in a single test file exceeds ten, it may be desirable to split it into separate test files. This will help maintain a consistent level of granularity across tests.
3535

@@ -46,12 +46,26 @@ Test cases use the following conventions:
4646
* Lines that are expected to produce a type checker error should have a comment starting with # E",
4747
either by itself or followed by an explanation after a colon (e.g., "# E: int is not a subtype
4848
of str"). Such explanatory comments are purely for human understanding, but type checkers are not
49-
expected to use their exact wording.
49+
expected to use their exact wording. There are several syntactic variations; see "Test Case Syntax"
50+
below.
5051
* Lines that may produce an error (e.g., because the spec allows multiple behaviors) should be
5152
marked with "# E?" instead of "# E".
5253
* If a test case tests conformance with a specific passage in the spec, that passage should be
5354
quoted in a comment prefixed with "# > ".
5455

56+
## Test Case Syntax
57+
58+
Test cases support the following special comments for declaring where errors should be raised:
59+
60+
* `# E`: an error must be raised on this line
61+
* `# E?`: an error may be raised on this line
62+
* `# E[tag]`, where `tag` is an arbitrary string: must appear multiple times in a file with the same tag.
63+
Exactly one line with this tag must raise an error.
64+
* `# E[tag+]`: like `# E[tag]`, but errors may be raised on multiple lines.
65+
66+
Each comment may be followed by a colon plus an explanation of the error; the explanation is ignored
67+
by the scoring system.
68+
5569
## Running the Conformance Test Tool
5670

5771
To run the conformance test suite:
@@ -60,13 +74,14 @@ To run the conformance test suite:
6074
* Switch to the `conformance` subdirectory and install all dependencies (`pip install -r requirements.txt`).
6175
* Switch to the `src` subdirectory and run `python main.py`.
6276

63-
Note that some type checkers may not run on some platforms. For example, pytype cannot be installed on Windows. If a type checker fails to install, tests will be skipped for that type checker.
77+
Note that some type checkers may not run on some platforms. If a type checker fails to install, tests will be skipped for that type checker.
78+
Currently, the only unsupported type checker is Pyre on Windows.
6479

6580
## Reporting Conformance Results
6681

6782
Different type checkers report errors in different ways (with different wording in error messages and different line numbers or character ranges for errors). This variation makes it difficult to fully automate test validation given that tests will want to check for both false positive and false negative type errors. Some level of manual inspection will therefore be needed to determine whether a type checker is fully conformant with all tests in any given test file. This "scoring" process is required only when the output of a test changes — e.g. when a new version of that type checker is released and the tests are rerun. We assume that the output of a type checker will be the same from one run to the next unless/until a new version is released that fixes or introduces a bug. In this case, the output will need to be manually inspected and the conformance results re-scored for those tests whose output has changed.
6883

69-
Conformance results are reported and summarized for each supported type checker. Currently, results are reported for mypy, pyre, pyright, and pytype. It is the goal and desire to add additional type checkers over time.
84+
Conformance results are reported and summarized for each supported type checker. Currently, results are reported for mypy, pyre, and pyright. It is the goal and desire to add additional type checkers over time.
7085

7186
## Adding a New Test Case
7287

conformance/requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ tomlkit
33
tqdm
44
pyright
55
mypy
6-
pyre-check
7-
pytype; platform_system != "Windows"
6+
pip
7+
pyre-check; platform_system != "Windows"

conformance/results/mypy/aliases_explicit.toml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ aliases_explicit.py:67: error: Bad number of arguments for type alias, expected
77
aliases_explicit.py:68: error: Bad number of arguments for type alias, expected 0, given 1 [type-arg]
88
aliases_explicit.py:69: error: Bad number of arguments for type alias, expected 1, given 2 [type-arg]
99
aliases_explicit.py:70: error: Bad number of arguments for type alias, expected 1, given 2 [type-arg]
10-
aliases_explicit.py:71: error: Can only replace ParamSpec with a parameter types list or another ParamSpec, got "int" [misc]
10+
aliases_explicit.py:71: error: Can only replace ParamSpec with a parameter types list or another ParamSpec, got "int" [valid-type]
1111
aliases_explicit.py:79: error: Invalid type alias: expression is not a valid type [valid-type]
1212
aliases_explicit.py:80: error: Bracketed expression "[...]" is not valid as a type [valid-type]
1313
aliases_explicit.py:81: error: Invalid type alias: expression is not a valid type [valid-type]
1414
aliases_explicit.py:82: error: Invalid type alias: expression is not a valid type [valid-type]
15-
aliases_explicit.py:83: error: Invalid type alias: expression is not a valid type [valid-type]
15+
aliases_explicit.py:83: error: Inline TypedDict is experimental, must be enabled with --enable-incomplete-feature=InlineTypedDict [misc]
16+
aliases_explicit.py:83: error: Name "b" is not defined [name-defined]
1617
aliases_explicit.py:84: error: Invalid type alias: expression is not a valid type [valid-type]
1718
aliases_explicit.py:85: error: Invalid type alias: expression is not a valid type [valid-type]
1819
aliases_explicit.py:86: error: Invalid type alias: expression is not a valid type [valid-type]
@@ -23,13 +24,11 @@ aliases_explicit.py:89: error: Invalid type: try using Literal[1] instead? [val
2324
aliases_explicit.py:90: error: Invalid type alias: expression is not a valid type [valid-type]
2425
aliases_explicit.py:90: error: Function "list" could always be true in boolean context [truthy-function]
2526
aliases_explicit.py:91: error: Invalid type alias: expression is not a valid type [valid-type]
26-
aliases_explicit.py:101: error: "<typing special form>" not callable [operator]
27+
aliases_explicit.py:101: error: "UnionType[list[Any], set[Any]]" not callable [operator]
2728
aliases_explicit.py:102: error: Bad number of arguments for type alias, expected 0, given 1 [type-arg]
2829
"""
2930
conformance_automated = "Fail"
3031
errors_diff = """
3132
Line 100: Expected 1 errors
3233
"""
33-
ignore_errors = [
34-
'Function "list" could always be true in boolean context',
35-
]
34+
ignore_errors = ["Function \"list\" could always be true in boolean context"]

conformance/results/mypy/aliases_implicit.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ aliases_implicit.py:76: error: Bad number of arguments for type alias, expected
44
aliases_implicit.py:77: error: Bad number of arguments for type alias, expected 0, given 1 [type-arg]
55
aliases_implicit.py:78: error: Bad number of arguments for type alias, expected 1, given 2 [type-arg]
66
aliases_implicit.py:79: error: Bad number of arguments for type alias, expected 1, given 2 [type-arg]
7-
aliases_implicit.py:80: error: Can only replace ParamSpec with a parameter types list or another ParamSpec, got "int" [misc]
7+
aliases_implicit.py:80: error: Can only replace ParamSpec with a parameter types list or another ParamSpec, got "int" [valid-type]
88
aliases_implicit.py:81: error: Type argument "str" of "GoodTypeAlias12" must be a subtype of "float" [type-var]
99
aliases_implicit.py:100: error: Function "list" could always be true in boolean context [truthy-function]
1010
aliases_implicit.py:106: error: Variable "aliases_implicit.BadTypeAlias1" is not valid as a type [valid-type]
@@ -35,7 +35,7 @@ aliases_implicit.py:118: error: Variable "aliases_implicit.BadTypeAlias13" is no
3535
aliases_implicit.py:118: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
3636
aliases_implicit.py:119: error: Variable "aliases_implicit.BadTypeAlias14" is not valid as a type [valid-type]
3737
aliases_implicit.py:119: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
38-
aliases_implicit.py:133: error: "<typing special form>" not callable [operator]
38+
aliases_implicit.py:133: error: "UnionType[list[Any], set[Any]]" not callable [operator]
3939
aliases_implicit.py:135: error: Bad number of arguments for type alias, expected 0, given 1 [type-arg]
4040
"""
4141
conformance_automated = "Pass"
Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
1-
conformant = "Pass"
1+
conformant = "Partial"
2+
notes = """
3+
`NewType`s are considered classes, not functions.
4+
"""
25
output = """
36
aliases_newtype.py:11: error: Argument 1 to "UserId" has incompatible type "str"; expected "int" [arg-type]
47
aliases_newtype.py:12: error: Incompatible types in assignment (expression has type "int", variable has type "UserId") [assignment]
5-
aliases_newtype.py:20: error: Cannot use isinstance() with NewType type [misc]
6-
aliases_newtype.py:23: error: Cannot subclass "NewType" [misc]
7-
aliases_newtype.py:32: error: String argument 1 "BadName" to NewType(...) does not match variable name "GoodName" [misc]
8-
aliases_newtype.py:38: error: "GoodNewType1" expects no type arguments, but 1 given [type-arg]
9-
aliases_newtype.py:44: error: Argument 2 to NewType(...) must be subclassable (got "int | str") [valid-newtype]
10-
aliases_newtype.py:47: error: Type variable "aliases_newtype.T" is unbound [valid-type]
11-
aliases_newtype.py:47: note: (Hint: Use "Generic[T]" or "Protocol[T]" base class to bind "T" inside a class)
12-
aliases_newtype.py:47: note: (Hint: Use "T" in function signature to bind "T" inside a function)
13-
aliases_newtype.py:49: error: NewType cannot be used with protocol classes [misc]
14-
aliases_newtype.py:51: error: Argument 2 to NewType(...) must be subclassable (got "Literal[7]") [valid-newtype]
15-
aliases_newtype.py:58: error: Argument 2 to NewType(...) must be subclassable (got "TD1") [valid-newtype]
16-
aliases_newtype.py:60: error: NewType(...) expects exactly two positional arguments [misc]
17-
aliases_newtype.py:62: error: Argument 2 to NewType(...) must be subclassable (got "Any") [valid-newtype]
8+
aliases_newtype.py:23: error: Cannot use isinstance() with NewType type [misc]
9+
aliases_newtype.py:26: error: Cannot subclass "NewType" [misc]
10+
aliases_newtype.py:35: error: String argument 1 "BadName" to NewType(...) does not match variable name "GoodName" [misc]
11+
aliases_newtype.py:41: error: "GoodNewType1" expects no type arguments, but 1 given [type-arg]
12+
aliases_newtype.py:47: error: Argument 2 to NewType(...) must be subclassable (got "int | str") [valid-newtype]
13+
aliases_newtype.py:50: error: Type variable "aliases_newtype.T" is unbound [valid-type]
14+
aliases_newtype.py:50: note: (Hint: Use "Generic[T]" or "Protocol[T]" base class to bind "T" inside a class)
15+
aliases_newtype.py:50: note: (Hint: Use "T" in function signature to bind "T" inside a function)
16+
aliases_newtype.py:52: error: NewType cannot be used with protocol classes [misc]
17+
aliases_newtype.py:54: error: Argument 2 to NewType(...) must be subclassable (got "Literal[7]") [valid-newtype]
18+
aliases_newtype.py:61: error: Argument 2 to NewType(...) must be subclassable (got "TD1") [valid-newtype]
19+
aliases_newtype.py:63: error: NewType(...) expects exactly two positional arguments [misc]
20+
aliases_newtype.py:65: error: Argument 2 to NewType(...) must be subclassable (got "Any") [valid-newtype]
1821
"""
19-
conformance_automated = "Pass"
22+
conformance_automated = "Fail"
2023
errors_diff = """
24+
Line 18: Expected 1 errors
2125
"""

0 commit comments

Comments
 (0)