Skip to content

Commit

Permalink
Move to pyright (#172)
Browse files Browse the repository at this point in the history
Following a discussion we have decided to move our static type checking from mypy to pyright. Pyright is a more complete checker, catching many things mypy missed, and is also more strongly supported, being a Microsoft library.
  • Loading branch information
abbiemery authored Jul 25, 2023
1 parent 8529b9c commit 8243ce2
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 23 deletions.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
**/.devcontainer
**/.mypy_cache
**/.pytest_cache
**/.tox
**/.venv
Expand Down
2 changes: 1 addition & 1 deletion .github/CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ The code in this repository conforms to standards set by the following tools:
- black_ for code formatting
- flake8_ for style checks
- isort_ for import ordering
- mypy_ for static type checking
- pyright_ for static type checking

Developers guide
----------------
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
install_options: -e .[dev]

- name: Lint
run: tox -e pre-commit,mypy
run: tox -e pre-commit,pyright

test:
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ nosetests.xml
coverage.xml
cov.xml
.pytest_cache/
.mypy_cache/

# Translations
*.mo
Expand Down
9 changes: 6 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
{
"python.languageServer": "Pylance",
"python.analysis.typeCheckingMode": "basic",
"python.analysis.diagnosticSeverityOverrides": {
"reportMissingModuleSource": "none"
},
"editor.defaultFormatter": "ms-python.python",
"python.linting.enabled": true,
"python.linting.pylintEnabled": false,
"python.linting.flake8Enabled": true,
"python.linting.mypyEnabled": true,
"python.linting.pydocstyleEnabled": true,
"python.linting.enabled": true,
"python.testing.pytestArgs": [],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"python.formatting.provider": "black",
"python.languageServer": "Pylance",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
.. _black: https://github.com/psf/black
.. _flake8: https://flake8.pycqa.org/en/latest/
.. _isort: https://github.com/PyCQA/isort
.. _mypy: http://mypy-lang.org/
.. _pyright: https://microsoft.github.io/pyright/#/
.. _pre-commit: https://pre-commit.com/
"""

Expand Down
8 changes: 4 additions & 4 deletions docs/developer/how-to/static-analysis.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Run static analysis using mypy
==============================
Run static analysis using pyright
=================================

Static type analysis is done with mypy_. It checks type definition in source
Static type analysis is done with pyright_. It checks type definition in source
files without running them, and highlights potential issues where types do not
match. You can run it with::

$ tox -e mypy
$ tox -e pyright
2 changes: 1 addition & 1 deletion docs/developer/reference/standards.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The code in this repository conforms to standards set by the following tools:
- black_ for code formatting
- flake8_ for style checks
- isort_ for import ordering
- mypy_ for static type checking
- pyright_ for static type checking

.. seealso::

Expand Down
13 changes: 6 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,13 @@ requires-python = ">=3.9"
[project.optional-dependencies]
dev = [
"black",
"mypy",
"pyright",
"flake8-isort",
"Flake8-pyproject",
"pipdeptree",
"pre-commit",
"pydata-sphinx-theme>=0.12",
"pytest-cov",
"pytest-mypy",
"pytest-flake8",
"pytest-black",
"pytest-asyncio",
Expand Down Expand Up @@ -68,8 +67,8 @@ name = "Callum Forrester"
[tool.setuptools_scm]
write_to = "src/tickit/_version.py"

[tool.mypy]
ignore_missing_imports = true # Ignore missing stubs in imported modules
[tool.pyright]
reportMissingImports = false # Ignore missing stubs in imported modules

[tool.isort]
float_to_top = true
Expand Down Expand Up @@ -122,19 +121,19 @@ legacy_tox_ini = """
[tox]
skipsdist=True
[testenv:{pre-commit,mypy,pytest,docs}]
[testenv:{pre-commit,pyright,pytest,docs}]
# Don't create a virtualenv for the command, requires tox-direct plugin
direct = True
passenv = *
allowlist_externals =
pytest
pre-commit
mypy
pyright
sphinx-build
sphinx-autobuild
commands =
pytest: pytest {posargs}
mypy: mypy src tests {posargs}
pyright: pyright src tests {posargs}
pre-commit: pre-commit run --all-files {posargs}
docs: sphinx-{posargs:build -EW --keep-going} -T docs build/html
"""
2 changes: 0 additions & 2 deletions src/tickit/adapters/interpreters/endpoints/http_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ class HttpEndpoint(Generic[AnyStr]):
method: str
interrupt: bool = False

# Type signature can become more specific if support is dropped for
# Python 3.7, see https://github.com/python/mypy/issues/708
def __call__(self, func: Callable) -> Callable:
"""Decorate a function for HTTP routing.
Expand Down
1 change: 0 additions & 1 deletion src/tickit/core/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
T = TypeVar("T")


# https://github.com/python/mypy/issues/708#issuecomment-647124281
class RaiseInterrupt(Protocol):
"""A raise_interrupt function that should be passed to `Adapter`."""

Expand Down

0 comments on commit 8243ce2

Please sign in to comment.