From 0be930739790a8ffe6a2943d6d89c122e61f95b9 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Thu, 10 Jun 2021 10:19:58 -0700 Subject: [PATCH 1/3] Add a stricter config pass for pyright --- .github/workflows/tests.yml | 11 +++- pyrightconfig.json | 2 +- pyrightconfig.stricter.json | 117 ++++++++++++++++++++++++++++++++++++ tests/README.md | 5 +- tests/pyright_test.py | 2 +- 5 files changed, 132 insertions(+), 5 deletions(-) create mode 100644 pyrightconfig.stricter.json diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index f99e55d27de2..8ba682c0bd66 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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. diff --git a/pyrightconfig.json b/pyrightconfig.json index b1163e35399c..fcdeaf92bf5e 100644 --- a/pyrightconfig.json +++ b/pyrightconfig.json @@ -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). diff --git a/pyrightconfig.stricter.json b/pyrightconfig.stricter.json new file mode 100644 index 000000000000..ea31c1097ff4 --- /dev/null +++ b/pyrightconfig.stricter.json @@ -0,0 +1,117 @@ +{ + "$schema": "https://raw.githubusercontent.com/microsoft/pyright/main/packages/vscode-pyright/schemas/pyrightconfig.schema.json", + "typeshedPath": ".", + "include": [ + "stdlib", + // Modules that pass this stricter mode. + "stubs/aiofiles", + "stubs/annoy", + "stubs/atomicwrites", + "stubs/bleach", + "stubs/cachetools", + "stubs/certifi", + "stubs/characteristic", + "stubs/chardet", + "stubs/click", + "stubs/click-spinner", + "stubs/colorama", + "stubs/contextvars", + "stubs/croniter", + "stubs/dataclasses", + "stubs/dateparser", + "stubs/DateTimeRange", + "stubs/decorator", + "stubs/Deprecated", + "stubs/docopt", + "stubs/emoji", + "stubs/filelock", + "stubs/first", + "stubs/freezegun", + "stubs/frozendict", + "stubs/geoip2", + "stubs/itsdangerous", + "stubs/JACK-Client", + "stubs/MarkupSafe", + "stubs/maxminddb", + "stubs/mock", + "stubs/mypy-extensions", + "stubs/nmap", + "stubs/orjson", + "stubs/pkg_resources", + "stubs/polib", + "stubs/pyaudio", + "stubs/pycurl", + "stubs/pyfarmhash", + "stubs/PyJWT", + "stubs/pyRFC3339", + "stubs/pysftp", + "stubs/python-gflags", + "stubs/python-slugify", + "stubs/pytz", + "stubs/retry", + "stubs/singledispatch", + "stubs/six", + "stubs/tabulate", + "stubs/termcolor", + "stubs/toml", + "stubs/typed-ast", + "stubs/tzlocal", + "stubs/ujson", + "stubs/waitress", + "stubs/xxhash", + ], + "exclude": [ + // Python 2 only modules. + "**/@python2", + // stdlib modules that are incomplete in some way. + "stdlib/sqlite3/dbapi2.pyi", + "stdlib/tkinter", + "stdlib/xml/dom", + "stdlib/xml/sax", + ], + "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" +} diff --git a/tests/README.md b/tests/README.md index 49c6fba51817..a89a130f77d6 100644 --- a/tests/README.md +++ b/tests/README.md @@ -47,8 +47,9 @@ 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. ``` ## check\_consistent.py diff --git a/tests/pyright_test.py b/tests/pyright_test.py index 415b381d784e..f811a9668b34 100755 --- a/tests/pyright_test.py +++ b/tests/pyright_test.py @@ -5,7 +5,7 @@ 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") From 029e637305f2ee2ec07e210d28b440f8d08a7003 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Thu, 10 Jun 2021 10:38:41 -0700 Subject: [PATCH 2/3] Flip exclude/include to opt stubs into stricter by default --- pyrightconfig.stricter.json | 90 ++++++++++++++----------------------- 1 file changed, 33 insertions(+), 57 deletions(-) diff --git a/pyrightconfig.stricter.json b/pyrightconfig.stricter.json index ea31c1097ff4..4d84e8dfe92f 100644 --- a/pyrightconfig.stricter.json +++ b/pyrightconfig.stricter.json @@ -3,71 +3,47 @@ "typeshedPath": ".", "include": [ "stdlib", - // Modules that pass this stricter mode. - "stubs/aiofiles", - "stubs/annoy", - "stubs/atomicwrites", - "stubs/bleach", - "stubs/cachetools", - "stubs/certifi", - "stubs/characteristic", - "stubs/chardet", - "stubs/click", - "stubs/click-spinner", - "stubs/colorama", - "stubs/contextvars", - "stubs/croniter", - "stubs/dataclasses", - "stubs/dateparser", - "stubs/DateTimeRange", - "stubs/decorator", - "stubs/Deprecated", - "stubs/docopt", - "stubs/emoji", - "stubs/filelock", - "stubs/first", - "stubs/freezegun", - "stubs/frozendict", - "stubs/geoip2", - "stubs/itsdangerous", - "stubs/JACK-Client", - "stubs/MarkupSafe", - "stubs/maxminddb", - "stubs/mock", - "stubs/mypy-extensions", - "stubs/nmap", - "stubs/orjson", - "stubs/pkg_resources", - "stubs/polib", - "stubs/pyaudio", - "stubs/pycurl", - "stubs/pyfarmhash", - "stubs/PyJWT", - "stubs/pyRFC3339", - "stubs/pysftp", - "stubs/python-gflags", - "stubs/python-slugify", - "stubs/pytz", - "stubs/retry", - "stubs/singledispatch", - "stubs/six", - "stubs/tabulate", - "stubs/termcolor", - "stubs/toml", - "stubs/typed-ast", - "stubs/tzlocal", - "stubs/ujson", - "stubs/waitress", - "stubs/xxhash", + "stubs" ], "exclude": [ // Python 2 only modules. "**/@python2", - // stdlib modules that are incomplete in some way. + "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, From 06451c46af288977b45384fa28304f811b846674 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Thu, 10 Jun 2021 10:58:10 -0700 Subject: [PATCH 3/3] Document stricter config in testing readme --- tests/README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/README.md b/tests/README.md index a89a130f77d6..a7453ae3aed6 100644 --- a/tests/README.md +++ b/tests/README.md @@ -52,6 +52,10 @@ but it uses the same pyright version and configuration as the CI. (.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: