Add pyright to test suite, pyrightconfig.json (#5059)

Co-authored-by: Sebastian Rittau <srittau@rittau.biz>
This commit is contained in:
Jake Bailey
2021-02-23 14:07:42 -08:00
committed by GitHub
parent a1f16da64e
commit c00c7258ea
5 changed files with 148 additions and 1 deletions

View File

@@ -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 }}

View File

@@ -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.

94
pyrightconfig.json Normal file
View File

@@ -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"
}

View File

@@ -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.

30
tests/pyright_test.py Executable file
View File

@@ -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()