Add a stricter config pass for pyright (#5612)

This commit is contained in:
Jake Bailey
2021-06-10 11:10:12 -07:00
committed by GitHub
parent cb76f32826
commit c4dc935b3f
5 changed files with 112 additions and 5 deletions

View File

@@ -76,11 +76,20 @@ jobs:
python-platform: ["Linux", "Windows", "Darwin"]
python-version: [3.6, 3.7, 3.8, 3.9, '3.10']
fail-fast: false
env:
PYRIGHT_VERSION: 1.1.148 # Must match pyright_test.py.
steps:
- uses: actions/checkout@v2
- uses: jakebailey/pyright-action@v1
with:
version: 1.1.144 # Must match pyright_test.py.
version: ${{ env.PYRIGHT_VERSION }}
python-platform: ${{ matrix.python-platform }}
python-version: ${{ matrix.python-version }}
no-comments: ${{ matrix.python-version != '3.9' || matrix.python-platform != 'Linux' }} # Having each job create the same comment is too noisy.
project: ./pyrightconfig.stricter.json
- uses: jakebailey/pyright-action@v1
with:
version: ${{ env.PYRIGHT_VERSION }}
python-platform: ${{ matrix.python-platform }}
python-version: ${{ matrix.python-version }}
no-comments: ${{ matrix.python-version != '3.9' || matrix.python-platform != 'Linux' }} # Having each job create the same comment is too noisy.

View File

@@ -56,7 +56,7 @@
"reportInvalidTypeVarUse": "error",
"reportPropertyTypeMismatch": "error",
"reportSelfClsParameterName": "error",
// Overloapping overloads cannot be enabled at this time because
// Overlapping overloads cannot be enabled at this time because
// of the "factions.Fraction.__pow__" method and "tasks.gather" function.
// Mypy's overlapping overload logic misses these issues (see mypy
// issue #10143 and #10157).

View File

@@ -0,0 +1,93 @@
{
"$schema": "https://raw.githubusercontent.com/microsoft/pyright/main/packages/vscode-pyright/schemas/pyrightconfig.schema.json",
"typeshedPath": ".",
"include": [
"stdlib",
"stubs"
],
"exclude": [
// Python 2 only modules.
"**/@python2",
"stubs/enum34",
"stubs/fb303",
"stubs/futures",
"stubs/ipaddress",
"stubs/kazoo",
"stubs/openssl-python",
"stubs/pathlib2",
"stubs/pymssql",
"stubs/Routes",
"stubs/scribe",
"stubs/tornado",
// Modules that are incomplete in some way.
"stdlib/sqlite3/dbapi2.pyi",
"stdlib/tkinter",
"stdlib/xml/dom",
"stdlib/xml/sax",
"stubs/backports",
"stubs/backports_abc",
"stubs/boto",
"stubs/cryptography",
"stubs/docutils",
"stubs/Flask",
"stubs/Jinja2",
"stubs/Markdown",
"stubs/Pillow",
"stubs/paramiko",
"stubs/protobuf",
"stubs/PyMySQL",
"stubs/python-dateutil",
"stubs/pyvmomi",
"stubs/PyYAML",
"stubs/redis",
"stubs/requests",
"stubs/simplejson",
"stubs/waitress",
"stubs/Werkzeug"
],
"typeCheckingMode": "basic",
"strictListInference": true,
"strictDictionaryInference": true,
"strictParameterNoneValue": true,
"reportFunctionMemberAccess": "error",
"reportMissingModuleSource": "none",
"reportMissingTypeStubs": "error",
"reportUnusedImport": "error",
"reportUnusedClass": "error",
"reportUnusedFunction": "error",
"reportUnusedVariable": "error",
"reportDuplicateImport": "error",
"reportOptionalSubscript": "error",
"reportOptionalMemberAccess": "error",
"reportOptionalCall": "error",
"reportOptionalIterable": "error",
"reportOptionalContextManager": "error",
"reportOptionalOperand": "error",
"reportUntypedFunctionDecorator": "error",
"reportUntypedClassDecorator": "error",
"reportUntypedBaseClass": "error",
"reportUntypedNamedTuple": "error",
"reportPrivateUsage": "error",
"reportConstantRedefinition": "error",
"reportIncompatibleMethodOverride": "error",
"reportIncompatibleVariableOverride": "error",
"reportInvalidStringEscapeSequence": "error",
"reportUnknownParameterType": "error",
"reportUnknownArgumentType": "error",
"reportUnknownLambdaType": "error",
"reportUnknownVariableType": "error",
"reportUnknownMemberType": "error",
"reportMissingTypeArgument": "error",
"reportUndefinedVariable": "error",
"reportUnboundVariable": "error",
"reportInvalidStubStatement": "error",
"reportUnsupportedDunderAll": "error",
"reportInvalidTypeVarUse": "error",
"reportPropertyTypeMismatch": "error",
"reportSelfClsParameterName": "error",
// Overlapping overloads cannot be enabled at this time because
// of the "factions.Fraction.__pow__" method and "tasks.gather" function.
// Mypy's overlapping overload logic misses these issues (see mypy
// issue #10143 and #10157).
"reportOverlappingOverload": "none"
}

View File

@@ -47,10 +47,15 @@ This test requires [Node.js](https://nodejs.org) to be installed. It is
currently not part of the CI,
but it uses the same pyright version and configuration as the CI.
```
(.venv3)$ python3 tests/pyright_test.py # Check all files
(.venv3)$ python3 tests/pyright_test.py stdlib/sys.pyi # Check one file
(.venv3)$ python3 tests/pyright_test.py # Check all files
(.venv3)$ python3 tests/pyright_test.py stdlib/sys.pyi # Check one file
(.venv3)$ python3 tests/pyright_test.py -p pyrightconfig.stricter.json # Check with the stricter config.
```
`pyrightconfig.stricter.json` is a stricter configuration that enables additional
checks that would typically fail on incomplete stubs (such as `Unknown` checks),
and is run on a subset of stubs (including the standard library).
## check\_consistent.py
Run using:

View File

@@ -5,7 +5,7 @@ import subprocess
import sys
from pathlib import Path
_PYRIGHT_VERSION = "1.1.144" # Must match tests.yml.
_PYRIGHT_VERSION = "1.1.148" # Must match tests.yml.
_WELL_KNOWN_FILE = Path("tests", "pyright_test.py")