From a8f3544a4a1bb7149bc811331041b393a3ccbfa3 Mon Sep 17 00:00:00 2001 From: ItsDrike Date: Tue, 16 Jul 2024 12:31:40 +0200 Subject: [PATCH] Add basedpyright --- .github/workflows/validation.yml | 5 ++++- .pre-commit-config.yaml | 10 ++++++++++ .vscode/extensions.json | 5 ++++- poetry.lock | 32 +++++++++++++++++++++++++++++++- pyproject.toml | 32 ++++++++++++++++++++++++++++++++ 5 files changed, 81 insertions(+), 3 deletions(-) diff --git a/.github/workflows/validation.yml b/.github/workflows/validation.yml index f0ec220..6d09287 100644 --- a/.github/workflows/validation.yml +++ b/.github/workflows/validation.yml @@ -33,10 +33,13 @@ jobs: restore-keys: "precommit-${{ runner.os }}-${{ steps.poetry_setup.outputs-python-version}}-" - name: Run pre-commit hooks - run: SKIP=ruff-linter,ruff-formatter pre-commit run --all-files + run: SKIP=ruff-linter,ruff-formatter,basedpyright pre-commit run --all-files - name: Run ruff linter run: ruff check --output-format=github --show-fixes --exit-non-zero-on-fix . - name: Run ruff formatter run: ruff format --diff . + + - name: Run basedpyright type checker + run: basedpyright --warnings . diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4a87244..8e6e7d0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -33,3 +33,13 @@ repos: language: system types_or: [python, pyi] require_serial: true + + - repo: local + hooks: + - id: basedpyright + name: Based Pyright + description: Run basedpyright type checker + entry: poetry run basedpyright --warnings + language: system + types: [python] + pass_filenames: false # pyright runs for the entire project, it can't run for single files diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 37b9f37..c6994d5 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -1,3 +1,6 @@ { - "recommendations": ["charliermarsh.ruff"] + "recommendations": [ + "charliermarsh.ruff", + "detachhead.basedpyright" + ] } diff --git a/poetry.lock b/poetry.lock index 50eb4c9..5858ad7 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,5 +1,19 @@ # This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand. +[[package]] +name = "basedpyright" +version = "1.13.3" +description = "static type checking for Python (but based)" +optional = false +python-versions = ">=3.8" +files = [ + {file = "basedpyright-1.13.3-py3-none-any.whl", hash = "sha256:3162c5a5f4fc99f9d53d76cbd8e24d31ad4b28b4fb26a58ab8be6e8b634c99a7"}, + {file = "basedpyright-1.13.3.tar.gz", hash = "sha256:728d7098250db8d18bc4b48df8f93dfd9c79d155c3c99d41256a6caa6a21232e"}, +] + +[package.dependencies] +nodejs-wheel-binaries = ">=20.13.1" + [[package]] name = "cfgv" version = "3.4.0" @@ -149,6 +163,22 @@ files = [ {file = "nodeenv-1.9.1.tar.gz", hash = "sha256:6ec12890a2dab7946721edbfbcd91f3319c6ccc9aec47be7c7e6b7011ee6645f"}, ] +[[package]] +name = "nodejs-wheel-binaries" +version = "20.15.1" +description = "unoffical Node.js package" +optional = false +python-versions = ">=3.7" +files = [ + {file = "nodejs_wheel_binaries-20.15.1-py2.py3-none-macosx_10_15_x86_64.whl", hash = "sha256:a04537555f59e53021f8a2b07fa7aaac29d7793b7fae7fbf561bf9a859f4c67a"}, + {file = "nodejs_wheel_binaries-20.15.1-py2.py3-none-macosx_11_0_arm64.whl", hash = "sha256:b5ff04efa56a3fcd1fd09b30f5236c12bd84c10fcb222f3c0e04e1d497342b70"}, + {file = "nodejs_wheel_binaries-20.15.1-py2.py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:29c3e172e3fde3c13e7509312c81700736304dbd250745d87f00e7506065f3a5"}, + {file = "nodejs_wheel_binaries-20.15.1-py2.py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9740f7456a43cb09521a1ac93a4355dc8282c41420f2d61ff631a01f39e2aa18"}, + {file = "nodejs_wheel_binaries-20.15.1-py2.py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:bf5e239676efabb2fbaeff2f36d0bad8e2379f260ef44e13ef2151d037e40af3"}, + {file = "nodejs_wheel_binaries-20.15.1-py2.py3-none-win_amd64.whl", hash = "sha256:624936171b1aa2e1cc6d1718b1caa089e943b54df16568fa2f4576d145ac279a"}, + {file = "nodejs_wheel_binaries-20.15.1.tar.gz", hash = "sha256:b2f25b4f0e9a827ae1af8218ab13a385e279c236faf7b7c821e969bb8f6b25e8"}, +] + [[package]] name = "packaging" version = "24.1" @@ -374,4 +404,4 @@ test = ["covdefaults (>=2.3)", "coverage (>=7.2.7)", "coverage-enable-subprocess [metadata] lock-version = "2.0" python-versions = "^3.12" -content-hash = "a5a77bd7b42497f36adc8c33bf1a9f87fece869157014783bf0839879e575863" +content-hash = "10c07e6a94506dc4ad46927e148980902b1f64be7df2a05265ce32e0543eb01e" diff --git a/pyproject.toml b/pyproject.toml index 8ef87d5..27b3184 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,6 +13,7 @@ python = "^3.12" [tool.poetry.group.lint.dependencies] ruff = "^0.3.2" pre-commit = "^3.6.2" +basedpyright = "^1.13.3" [tool.poetry.group.test.dependencies] pytest = "^8.1.1" @@ -125,6 +126,37 @@ max-statements = 75 [tool.ruff.format] line-ending = "lf" +[tool.basedpyright] +pythonPlatform = "All" +pythonVersion = "3.12" +typeCheckingMode = "all" + +# Diagnostic behavior settings +strictListInference = false +strictDictionaryInference = false +strictSetInference = false +analyzeUnannotatedFunctions = true +strictParameterNoneValue = true +enableTypeIgnoreComments = true +deprecateTypingAliases = true +enableExperimentalFeatures = false +disableBytesTypePromotions = true + +# Diagnostic rules +reportAny = false +reportImplicitStringConcatenation = false +reportUnreachable = "information" +reportMissingTypeStubs = "information" +reportUninitializedInstanceVariable = false # until https://github.com/DetachHead/basedpyright/issues/491 +reportMissingParameterType = false # ruff's flake8-annotations (ANN) already covers this + gives us more control + +# Unknown type reporting rules (too strict for most code-bases) +reportUnknownArgumentType = false +reportUnknownVariableType = false +reportUnknownMemberType = false +reportUnknownParameterType = false +reportUnknownLambdaType = false + [tool.pytest.ini_options] minversion = "6.0" asyncio_mode = "auto"