From c00c7258ea6c45ab8f00583d603c784b87a425a5 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Tue, 23 Feb 2021 14:07:42 -0800 Subject: [PATCH] Add pyright to test suite, pyrightconfig.json (#5059) Co-authored-by: Sebastian Rittau --- .github/workflows/tests.yml | 11 ++++ README.md | 11 +++- pyrightconfig.json | 94 ++++++++++++++++++++++++++++++++++ tests/pyright_exclude_list.txt | 3 ++ tests/pyright_test.py | 30 +++++++++++ 5 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 pyrightconfig.json create mode 100644 tests/pyright_exclude_list.txt create mode 100755 tests/pyright_test.py diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 41e2e2163..164aeaf79 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -85,6 +85,17 @@ jobs: - uses: actions/setup-python@v2 - run: ./tests/mypy_test_suite.py + pyright: + 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: name: Check stdlib with stubtest runs-on: ${{ matrix.os }} diff --git a/README.md b/README.md index e99075537..e8884fa74 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/pyrightconfig.json b/pyrightconfig.json new file mode 100644 index 000000000..313549aac --- /dev/null +++ b/pyrightconfig.json @@ -0,0 +1,94 @@ +{ + "typeshedPath": ".", + "include": [ + "stdlib", + "stubs" + ], + "exclude": [ + "**/@python2", + "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", + "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": "none", + "reportOverlappingOverload": "none", + "reportPropertyTypeMismatch": "none", + "reportSelfClsParameterName": "none" +} diff --git a/tests/pyright_exclude_list.txt b/tests/pyright_exclude_list.txt new file mode 100644 index 000000000..ad8bceb69 --- /dev/null +++ b/tests/pyright_exclude_list.txt @@ -0,0 +1,3 @@ +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. diff --git a/tests/pyright_test.py b/tests/pyright_test.py new file mode 100755 index 000000000..926fb952d --- /dev/null +++ b/tests/pyright_test.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 + +import subprocess +import sys +from pathlib import Path + + +_WELL_KNOWN_FILE = Path("tests", "pyright_test.py") +_PYRIGHT_COMMAND = ["npx", "-p", "pyright@1.1.114", "pyright"] + + +def main() -> None: + assert_npm_is_installed() + ret = subprocess.run(_PYRIGHT_COMMAND).returncode + 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) + + +if __name__ == "__main__": + main()