Skip to content

Commit c4dc935

Browse files
authored
Add a stricter config pass for pyright (#5612)
1 parent cb76f32 commit c4dc935

File tree

5 files changed

+112
-5
lines changed

5 files changed

+112
-5
lines changed

.github/workflows/tests.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,20 @@ jobs:
7676
python-platform: ["Linux", "Windows", "Darwin"]
7777
python-version: [3.6, 3.7, 3.8, 3.9, '3.10']
7878
fail-fast: false
79+
env:
80+
PYRIGHT_VERSION: 1.1.148 # Must match pyright_test.py.
7981
steps:
8082
- uses: actions/checkout@v2
8183
- uses: jakebailey/pyright-action@v1
8284
with:
83-
version: 1.1.144 # Must match pyright_test.py.
85+
version: ${{ env.PYRIGHT_VERSION }}
86+
python-platform: ${{ matrix.python-platform }}
87+
python-version: ${{ matrix.python-version }}
88+
no-comments: ${{ matrix.python-version != '3.9' || matrix.python-platform != 'Linux' }} # Having each job create the same comment is too noisy.
89+
project: ./pyrightconfig.stricter.json
90+
- uses: jakebailey/pyright-action@v1
91+
with:
92+
version: ${{ env.PYRIGHT_VERSION }}
8493
python-platform: ${{ matrix.python-platform }}
8594
python-version: ${{ matrix.python-version }}
8695
no-comments: ${{ matrix.python-version != '3.9' || matrix.python-platform != 'Linux' }} # Having each job create the same comment is too noisy.

pyrightconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"reportInvalidTypeVarUse": "error",
5757
"reportPropertyTypeMismatch": "error",
5858
"reportSelfClsParameterName": "error",
59-
// Overloapping overloads cannot be enabled at this time because
59+
// Overlapping overloads cannot be enabled at this time because
6060
// of the "factions.Fraction.__pow__" method and "tasks.gather" function.
6161
// Mypy's overlapping overload logic misses these issues (see mypy
6262
// issue #10143 and #10157).

pyrightconfig.stricter.json

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/microsoft/pyright/main/packages/vscode-pyright/schemas/pyrightconfig.schema.json",
3+
"typeshedPath": ".",
4+
"include": [
5+
"stdlib",
6+
"stubs"
7+
],
8+
"exclude": [
9+
// Python 2 only modules.
10+
"**/@python2",
11+
"stubs/enum34",
12+
"stubs/fb303",
13+
"stubs/futures",
14+
"stubs/ipaddress",
15+
"stubs/kazoo",
16+
"stubs/openssl-python",
17+
"stubs/pathlib2",
18+
"stubs/pymssql",
19+
"stubs/Routes",
20+
"stubs/scribe",
21+
"stubs/tornado",
22+
// Modules that are incomplete in some way.
23+
"stdlib/sqlite3/dbapi2.pyi",
24+
"stdlib/tkinter",
25+
"stdlib/xml/dom",
26+
"stdlib/xml/sax",
27+
"stubs/backports",
28+
"stubs/backports_abc",
29+
"stubs/boto",
30+
"stubs/cryptography",
31+
"stubs/docutils",
32+
"stubs/Flask",
33+
"stubs/Jinja2",
34+
"stubs/Markdown",
35+
"stubs/Pillow",
36+
"stubs/paramiko",
37+
"stubs/protobuf",
38+
"stubs/PyMySQL",
39+
"stubs/python-dateutil",
40+
"stubs/pyvmomi",
41+
"stubs/PyYAML",
42+
"stubs/redis",
43+
"stubs/requests",
44+
"stubs/simplejson",
45+
"stubs/waitress",
46+
"stubs/Werkzeug"
47+
],
48+
"typeCheckingMode": "basic",
49+
"strictListInference": true,
50+
"strictDictionaryInference": true,
51+
"strictParameterNoneValue": true,
52+
"reportFunctionMemberAccess": "error",
53+
"reportMissingModuleSource": "none",
54+
"reportMissingTypeStubs": "error",
55+
"reportUnusedImport": "error",
56+
"reportUnusedClass": "error",
57+
"reportUnusedFunction": "error",
58+
"reportUnusedVariable": "error",
59+
"reportDuplicateImport": "error",
60+
"reportOptionalSubscript": "error",
61+
"reportOptionalMemberAccess": "error",
62+
"reportOptionalCall": "error",
63+
"reportOptionalIterable": "error",
64+
"reportOptionalContextManager": "error",
65+
"reportOptionalOperand": "error",
66+
"reportUntypedFunctionDecorator": "error",
67+
"reportUntypedClassDecorator": "error",
68+
"reportUntypedBaseClass": "error",
69+
"reportUntypedNamedTuple": "error",
70+
"reportPrivateUsage": "error",
71+
"reportConstantRedefinition": "error",
72+
"reportIncompatibleMethodOverride": "error",
73+
"reportIncompatibleVariableOverride": "error",
74+
"reportInvalidStringEscapeSequence": "error",
75+
"reportUnknownParameterType": "error",
76+
"reportUnknownArgumentType": "error",
77+
"reportUnknownLambdaType": "error",
78+
"reportUnknownVariableType": "error",
79+
"reportUnknownMemberType": "error",
80+
"reportMissingTypeArgument": "error",
81+
"reportUndefinedVariable": "error",
82+
"reportUnboundVariable": "error",
83+
"reportInvalidStubStatement": "error",
84+
"reportUnsupportedDunderAll": "error",
85+
"reportInvalidTypeVarUse": "error",
86+
"reportPropertyTypeMismatch": "error",
87+
"reportSelfClsParameterName": "error",
88+
// Overlapping overloads cannot be enabled at this time because
89+
// of the "factions.Fraction.__pow__" method and "tasks.gather" function.
90+
// Mypy's overlapping overload logic misses these issues (see mypy
91+
// issue #10143 and #10157).
92+
"reportOverlappingOverload": "none"
93+
}

tests/README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,15 @@ This test requires [Node.js](https://nodejs.org) to be installed. It is
4747
currently not part of the CI,
4848
but it uses the same pyright version and configuration as the CI.
4949
```
50-
(.venv3)$ python3 tests/pyright_test.py # Check all files
51-
(.venv3)$ python3 tests/pyright_test.py stdlib/sys.pyi # Check one file
50+
(.venv3)$ python3 tests/pyright_test.py # Check all files
51+
(.venv3)$ python3 tests/pyright_test.py stdlib/sys.pyi # Check one file
52+
(.venv3)$ python3 tests/pyright_test.py -p pyrightconfig.stricter.json # Check with the stricter config.
5253
```
5354

55+
`pyrightconfig.stricter.json` is a stricter configuration that enables additional
56+
checks that would typically fail on incomplete stubs (such as `Unknown` checks),
57+
and is run on a subset of stubs (including the standard library).
58+
5459
## check\_consistent.py
5560

5661
Run using:

tests/pyright_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import sys
66
from pathlib import Path
77

8-
_PYRIGHT_VERSION = "1.1.144" # Must match tests.yml.
8+
_PYRIGHT_VERSION = "1.1.148" # Must match tests.yml.
99
_WELL_KNOWN_FILE = Path("tests", "pyright_test.py")
1010

1111

0 commit comments

Comments
 (0)