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
Copy file name to clipboardExpand all lines: conformance/README.md
+39-24Lines changed: 39 additions & 24 deletions
Original file line number
Diff line number
Diff line change
@@ -2,34 +2,34 @@
2
2
3
3
## Motivation
4
4
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.
6
6
7
7
Accompanying the typing specification is this conformance test suite which validates the behavior of static type checkers against the specification.
8
8
9
9
## Structure & Name
10
10
11
11
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.
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.
35
35
@@ -46,12 +46,26 @@ Test cases use the following conventions:
46
46
* Lines that are expected to produce a type checker error should have a comment starting with # E",
47
47
either by itself or followed by an explanation after a colon (e.g., "# E: int is not a subtype
48
48
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.
50
51
* Lines that may produce an error (e.g., because the spec allows multiple behaviors) should be
51
52
marked with "# E?" instead of "# E".
52
53
* If a test case tests conformance with a specific passage in the spec, that passage should be
53
54
quoted in a comment prefixed with "# > ".
54
55
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
+
55
69
## Running the Conformance Test Tool
56
70
57
71
To run the conformance test suite:
@@ -60,13 +74,14 @@ To run the conformance test suite:
60
74
* Switch to the `conformance` subdirectory and install all dependencies (`pip install -r requirements.txt`).
61
75
* Switch to the `src` subdirectory and run `python main.py`.
62
76
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.
64
79
65
80
## Reporting Conformance Results
66
81
67
82
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.
68
83
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.
0 commit comments