From 1200288cc58b0349aa2919099b18c4b645de902c Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Mon, 22 Feb 2021 20:11:53 +0100 Subject: [PATCH 01/10] First draft of pyright tests --- README.md | 11 ++++++++- tests/pyright_test.py | 52 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100755 tests/pyright_test.py diff --git a/README.md b/README.md index e990755376d3..e8884fa74f0f 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,8 @@ There are several tests: tests typeshed with [mypy](https://github.com/python/mypy/) - `tests/pytype_test.py` tests typeshed with [pytype](https://github.com/google/pytype/). +- `tests/pyright_test.py` tests typeshed with +[pyright](https://github.com/microsoft/pyright). - `tests/mypy_self_check.py` checks mypy's code base using this version of typeshed. - `tests/mypy_test_suite.py` runs a subset of mypy's test suite using this version of @@ -121,7 +123,7 @@ consistent with each other. Run: ``` -$ python3.6 -m venv .venv3 +$ python3 -m venv .venv3 $ source .venv3/bin/activate (.venv3)$ pip install -U pip (.venv3)$ pip install -r requirements-tests-py3.txt @@ -129,6 +131,9 @@ $ source .venv3/bin/activate This will install mypy (you need the latest master branch from GitHub), typed-ast, flake8 (and plugins), pytype, black and isort. +If you want to run the pyright tests, you need to have +[Node.js](https://nodejs.org/) installed. + ### mypy_test.py This test requires Python 3.6 or higher; Python 3.6.1 or higher is recommended. @@ -160,6 +165,10 @@ Run using: `(.venv3)$ python3 tests/pytype_test.py` This test works similarly to `mypy_test.py`, except it uses `pytype`. +### pyright\_test.py + +This test requires Node.js to be installed. + ### mypy_self_check.py This test requires Python 3.6 or higher; Python 3.6.1 or higher is recommended. diff --git a/tests/pyright_test.py b/tests/pyright_test.py new file mode 100755 index 000000000000..94e0cb0fe38d --- /dev/null +++ b/tests/pyright_test.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python3 + +import os +import subprocess +import sys +from pathlib import Path +from typing import Iterable, List + + +_WELL_KNOWN_FILE = Path("tests", "pyright_test.py") +_PYRIGHT_COMMAND = ["npx", "-p", "pyright@1.1.113", "pyright"] + + +def main() -> None: + assert_npm_is_installed() + files = find_stubs() + ret = run_pyright(files) + sys.exit(ret) + + +def assert_npm_is_installed() -> None: + if not _WELL_KNOWN_FILE.exists(): + print("pyright_test.py must be run from the typeshed root directory", file=sys.stderr) + sys.exit(1) + try: + subprocess.run(["npx", "--version"]) + except OSError: + print("error running npx; is Node.js installed?", file=sys.stderr) + sys.exit(1) + + +def find_stubs() -> List[str]: + files: List[str] = [] + for top in ["stdlib", "stubs"]: + for dirpath, dirnames, filenames in os.walk(top): + for fn in filenames: + if fn.endswith(".pyi"): + files.append(os.path.join(dirpath, fn)) + try: + dirnames.remove("@python2") + except ValueError: + pass + return files + + +def run_pyright(files: Iterable[str]) -> int: + full_args = _PYRIGHT_COMMAND + list(files) + return subprocess.run(full_args).returncode + + +if __name__ == "__main__": + main() From 55fbead5997085163e4faac661fcab93dec347bb Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Mon, 22 Feb 2021 20:14:03 +0100 Subject: [PATCH 02/10] Run pyright test in CI --- .github/workflows/tests.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 41e2e2163ff7..82fabf3de3b8 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -85,6 +85,14 @@ jobs: - uses: actions/setup-python@v2 - run: ./tests/mypy_test_suite.py + pyright: + name: Run the pyright test suite + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + - run: ./tests/pyright_test.py + stubtest: name: Check stdlib with stubtest runs-on: ${{ matrix.os }} From b244bf4968114bb5ac2a3d39af7ac138b3527551 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Tue, 23 Feb 2021 09:41:22 -0800 Subject: [PATCH 03/10] Use pyrightconfig.json, set node version in workflow --- .github/workflows/tests.yml | 5 ++++- pyrightconfig.json | 9 +++++++++ tests/pyright_exclude_list.txt | 1 + tests/pyright_test.py | 24 +----------------------- 4 files changed, 15 insertions(+), 24 deletions(-) create mode 100644 pyrightconfig.json create mode 100644 tests/pyright_exclude_list.txt diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 82fabf3de3b8..164aeaf79f3d 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -86,11 +86,14 @@ jobs: - run: ./tests/mypy_test_suite.py pyright: - name: Run the pyright test suite + name: Run pyright against the stubs runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: actions/setup-python@v2 + - uses: actions/setup-node@v2 + with: + node-version: '14' - run: ./tests/pyright_test.py stubtest: diff --git a/pyrightconfig.json b/pyrightconfig.json new file mode 100644 index 000000000000..187f18eb57af --- /dev/null +++ b/pyrightconfig.json @@ -0,0 +1,9 @@ +{ + "include": [ + "stdlib", + "stubs" + ], + "ignore": [ + "**/@python2" + ] +} diff --git a/tests/pyright_exclude_list.txt b/tests/pyright_exclude_list.txt new file mode 100644 index 000000000000..537befdcd8f7 --- /dev/null +++ b/tests/pyright_exclude_list.txt @@ -0,0 +1 @@ +# See pyrightconfig.json at the repo root. diff --git a/tests/pyright_test.py b/tests/pyright_test.py index 94e0cb0fe38d..789e32c53e13 100755 --- a/tests/pyright_test.py +++ b/tests/pyright_test.py @@ -1,10 +1,8 @@ #!/usr/bin/env python3 -import os import subprocess import sys from pathlib import Path -from typing import Iterable, List _WELL_KNOWN_FILE = Path("tests", "pyright_test.py") @@ -13,8 +11,7 @@ def main() -> None: assert_npm_is_installed() - files = find_stubs() - ret = run_pyright(files) + ret = subprocess.run(_PYRIGHT_COMMAND).returncode sys.exit(ret) @@ -29,24 +26,5 @@ def assert_npm_is_installed() -> None: sys.exit(1) -def find_stubs() -> List[str]: - files: List[str] = [] - for top in ["stdlib", "stubs"]: - for dirpath, dirnames, filenames in os.walk(top): - for fn in filenames: - if fn.endswith(".pyi"): - files.append(os.path.join(dirpath, fn)) - try: - dirnames.remove("@python2") - except ValueError: - pass - return files - - -def run_pyright(files: Iterable[str]) -> int: - full_args = _PYRIGHT_COMMAND + list(files) - return subprocess.run(full_args).returncode - - if __name__ == "__main__": main() From 0c1b75abbc94b7b9e0d5880ad97c1a5c0f2dff33 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Tue, 23 Feb 2021 10:09:53 -0800 Subject: [PATCH 04/10] Exclude (not ignore) @python2 directories --- pyrightconfig.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyrightconfig.json b/pyrightconfig.json index 187f18eb57af..eeb05291dc3c 100644 --- a/pyrightconfig.json +++ b/pyrightconfig.json @@ -3,7 +3,7 @@ "stdlib", "stubs" ], - "ignore": [ - "**/@python2" + "exclude": [ + "**/@python2/**" ] } From ce1cd62febe737d7d02e1c8f81e58615e911c024 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Tue, 23 Feb 2021 10:12:57 -0800 Subject: [PATCH 05/10] Set typeshed path to repo root --- pyrightconfig.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyrightconfig.json b/pyrightconfig.json index eeb05291dc3c..a0f54ee46279 100644 --- a/pyrightconfig.json +++ b/pyrightconfig.json @@ -5,5 +5,6 @@ ], "exclude": [ "**/@python2/**" - ] + ], + "typeshedPath": "." } From c02e86d0dd52fb25ede84222c7768d1234a522ee Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Tue, 23 Feb 2021 10:41:44 -0800 Subject: [PATCH 06/10] Updates from Eric --- pyrightconfig.json | 100 ++++++++++++++++++++++++++++++--- tests/pyright_exclude_list.txt | 4 +- 2 files changed, 95 insertions(+), 9 deletions(-) diff --git a/pyrightconfig.json b/pyrightconfig.json index a0f54ee46279..57ba315457ba 100644 --- a/pyrightconfig.json +++ b/pyrightconfig.json @@ -1,10 +1,94 @@ { - "include": [ - "stdlib", - "stubs" - ], - "exclude": [ - "**/@python2/**" - ], - "typeshedPath": "." + "typeshedPath": ".", + "include": [ + "stdlib", + "stubs" + ], + "exclude": [ + "**/@python2", + "stdlib/crypto/__init__.pyi", + "stdlib/encodings/__init__.pyi", + "stdlib/sqlite3/dbapi2.pyi", + "stdlib/tkinter", + "stdlib/xml/dom", + "stdlib/xml/sax", + "stubs/backports", + "stubs/backports_abc", + "stubs/boto", + "stubs/cachetools", + "stubs/chardet", + "stubs/click", + "stubs/cryptography", + "stubs/dateparser", + "stubs/DateTimeRange", + "stubs/decorator", + "stubs/docutils", + "stubs/fb303", + "stubs/Flask", + "stubs/frozendict", + "stubs/Jinja2", + "stubs/kazoo", + "stubs/Markdown", + "stubs/MarkupSafe", + "stubs/mock", + "stubs/nmap", + "stubs/openssl-python", + "stubs/polib", + "stubs/paramiko", + "stubs/protobuf", + "stubs/pymssql", + "stubs/PyMySQL", + "stubs/python-dateutil", + "stubs/pyvmomi", + "stubs/PyYAML", + "stubs/redis", + "stubs/requests", + "stubs/Routes", + "stubs/scribe", + "stubs/simplejson", + "stubs/tornado", + "stubs/waitress", + "stubs/Werkzeug" + ], + "pythonVersion": "3.9", + "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": "none", + "reportOverlappingOverload": "none", + "reportPropertyTypeMismatch": "none", + "reportSelfClsParameterName": "none" } diff --git a/tests/pyright_exclude_list.txt b/tests/pyright_exclude_list.txt index 537befdcd8f7..ad8bceb69c57 100644 --- a/tests/pyright_exclude_list.txt +++ b/tests/pyright_exclude_list.txt @@ -1 +1,3 @@ -# See pyrightconfig.json at the repo root. +Pyright is configured using a "pyrightconfig.json" file. You will find +it at the root of the repo. It contains an "exclude" section that accepts +globs for specifying which files and/or directories to exclude from analysis. From 58cbc8661d01dfd72cc5008ba64f78652246481b Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Tue, 23 Feb 2021 10:46:27 -0800 Subject: [PATCH 07/10] Update indention to match other config files --- pyrightconfig.json | 184 ++++++++++++++++++++++----------------------- 1 file changed, 92 insertions(+), 92 deletions(-) diff --git a/pyrightconfig.json b/pyrightconfig.json index 57ba315457ba..af664b6fb022 100644 --- a/pyrightconfig.json +++ b/pyrightconfig.json @@ -1,94 +1,94 @@ { - "typeshedPath": ".", - "include": [ - "stdlib", - "stubs" - ], - "exclude": [ - "**/@python2", - "stdlib/crypto/__init__.pyi", - "stdlib/encodings/__init__.pyi", - "stdlib/sqlite3/dbapi2.pyi", - "stdlib/tkinter", - "stdlib/xml/dom", - "stdlib/xml/sax", - "stubs/backports", - "stubs/backports_abc", - "stubs/boto", - "stubs/cachetools", - "stubs/chardet", - "stubs/click", - "stubs/cryptography", - "stubs/dateparser", - "stubs/DateTimeRange", - "stubs/decorator", - "stubs/docutils", - "stubs/fb303", - "stubs/Flask", - "stubs/frozendict", - "stubs/Jinja2", - "stubs/kazoo", - "stubs/Markdown", - "stubs/MarkupSafe", - "stubs/mock", - "stubs/nmap", - "stubs/openssl-python", - "stubs/polib", - "stubs/paramiko", - "stubs/protobuf", - "stubs/pymssql", - "stubs/PyMySQL", - "stubs/python-dateutil", - "stubs/pyvmomi", - "stubs/PyYAML", - "stubs/redis", - "stubs/requests", - "stubs/Routes", - "stubs/scribe", - "stubs/simplejson", - "stubs/tornado", - "stubs/waitress", - "stubs/Werkzeug" - ], - "pythonVersion": "3.9", - "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": "none", - "reportOverlappingOverload": "none", - "reportPropertyTypeMismatch": "none", - "reportSelfClsParameterName": "none" + "typeshedPath": ".", + "include": [ + "stdlib", + "stubs" + ], + "exclude": [ + "**/@python2", + "stdlib/crypto/__init__.pyi", + "stdlib/encodings/__init__.pyi", + "stdlib/sqlite3/dbapi2.pyi", + "stdlib/tkinter", + "stdlib/xml/dom", + "stdlib/xml/sax", + "stubs/backports", + "stubs/backports_abc", + "stubs/boto", + "stubs/cachetools", + "stubs/chardet", + "stubs/click", + "stubs/cryptography", + "stubs/dateparser", + "stubs/DateTimeRange", + "stubs/decorator", + "stubs/docutils", + "stubs/fb303", + "stubs/Flask", + "stubs/frozendict", + "stubs/Jinja2", + "stubs/kazoo", + "stubs/Markdown", + "stubs/MarkupSafe", + "stubs/mock", + "stubs/nmap", + "stubs/openssl-python", + "stubs/polib", + "stubs/paramiko", + "stubs/protobuf", + "stubs/pymssql", + "stubs/PyMySQL", + "stubs/python-dateutil", + "stubs/pyvmomi", + "stubs/PyYAML", + "stubs/redis", + "stubs/requests", + "stubs/Routes", + "stubs/scribe", + "stubs/simplejson", + "stubs/tornado", + "stubs/waitress", + "stubs/Werkzeug" + ], + "pythonVersion": "3.9", + "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": "none", + "reportOverlappingOverload": "none", + "reportPropertyTypeMismatch": "none", + "reportSelfClsParameterName": "none" } From 20a2e215732bac97ce5d9fac0f14c22716f83fba Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Tue, 23 Feb 2021 11:00:33 -0800 Subject: [PATCH 08/10] Update typeCheckingMode to explicitly specify basic --- pyrightconfig.json | 1 + 1 file changed, 1 insertion(+) diff --git a/pyrightconfig.json b/pyrightconfig.json index af664b6fb022..87d21ca21d21 100644 --- a/pyrightconfig.json +++ b/pyrightconfig.json @@ -51,6 +51,7 @@ "stubs/Werkzeug" ], "pythonVersion": "3.9", + "typeCheckingMode": "basic", "strictListInference": true, "strictDictionaryInference": true, "strictParameterNoneValue": true, From 6d537f6516bdadfec142055c4c8b40b4fe442f16 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Tue, 23 Feb 2021 12:32:19 -0800 Subject: [PATCH 09/10] Bump to pyright 1.1.114 --- tests/pyright_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/pyright_test.py b/tests/pyright_test.py index 789e32c53e13..926fb952da45 100755 --- a/tests/pyright_test.py +++ b/tests/pyright_test.py @@ -6,7 +6,7 @@ _WELL_KNOWN_FILE = Path("tests", "pyright_test.py") -_PYRIGHT_COMMAND = ["npx", "-p", "pyright@1.1.113", "pyright"] +_PYRIGHT_COMMAND = ["npx", "-p", "pyright@1.1.114", "pyright"] def main() -> None: From 1bc46f0513a4309bab1a454c66cbdb3b7e8a7bdf Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Tue, 23 Feb 2021 13:23:10 -0800 Subject: [PATCH 10/10] Remove unused exclude --- pyrightconfig.json | 1 - 1 file changed, 1 deletion(-) diff --git a/pyrightconfig.json b/pyrightconfig.json index 87d21ca21d21..313549aac8e1 100644 --- a/pyrightconfig.json +++ b/pyrightconfig.json @@ -6,7 +6,6 @@ ], "exclude": [ "**/@python2", - "stdlib/crypto/__init__.pyi", "stdlib/encodings/__init__.pyi", "stdlib/sqlite3/dbapi2.pyi", "stdlib/tkinter",