From 0855c6fbb363fa5ac6e26212e96c40bdfb1c4f56 Mon Sep 17 00:00:00 2001 From: ItsDrike Date: Sat, 13 Jul 2024 12:59:17 +0200 Subject: [PATCH 1/2] basedpyright: Treat warnings as errors --- .github/workflows/validation.yml | 2 +- .pre-commit-config.yml | 6 +++--- pyproject.toml | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/validation.yml b/.github/workflows/validation.yml index 1621485..6b06b7f 100644 --- a/.github/workflows/validation.yml +++ b/.github/workflows/validation.yml @@ -46,4 +46,4 @@ jobs: run: slotscheck -m mcproto - name: Run basedpyright type checker - run: basedpyright . + run: basedpyright --warnings . diff --git a/.pre-commit-config.yml b/.pre-commit-config.yml index 9b6641b..cd00636 100644 --- a/.pre-commit-config.yml +++ b/.pre-commit-config.yml @@ -36,9 +36,9 @@ repos: - repo: local hooks: - id: basedpyright - name: BasedPyright - description: Run BasedPyright type checker - entry: poetry run 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/pyproject.toml b/pyproject.toml index e574b08..ac67753 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -204,7 +204,7 @@ cmd = "pytest -v --failed-first" help = "Run pytest tests" [tool.poe.tasks.pyright] -cmd = "basedpyright ." +cmd = "basedpyright --warnings ." help = "Run BasedPyright type-checker" [tool.poe.tasks.retest] From 97f7f5da2a5728b4a7500a12cc6a2de98381da6c Mon Sep 17 00:00:00 2001 From: ItsDrike Date: Sat, 13 Jul 2024 13:01:45 +0200 Subject: [PATCH 2/2] Move to a much stricter pyright configuration This moves us from using the "standard" type-checking mode (which has a lot of the diagnostic rules disabled, which meant we were almost in a whitelist-based system, where most diagnostic rules were disabled unless explicitly enabled) to "all" (where all diagnotic rules are enabled, except for those explicitly disabled, moving us to a blacklist-based system). The current configuration here is very strict and might not fit all code-bases, but it will work very well for new projects, as this strictness, while slightly annoying sometimes, forces a lot better and more correct typing to the previous set of rules. This template still leaves the rules for reporting unknown types disabled, as these are incredibly strict and while they can definitely be beneficial, for most people it's too big of an annoyance for what it's worth. --- pyproject.toml | 47 ++++++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index ac67753..909e5bd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -69,8 +69,6 @@ ignore = [ "D416", # Section name should end with a colon "D417", # Missing argument descrition in the docstring - "ANN002", # Missing type annotation for *args - "ANN003", # Missing type annotation for **kwargs "ANN101", # Missing type annotation for self in method "ANN102", # Missing type annotation for cls in classmethod "ANN204", # Missing return type annotation for special method @@ -131,25 +129,36 @@ max-statements = 250 [tool.ruff.format] line-ending = "lf" -[tool.pyright] +[tool.basedpyright] +pythonPlatform = "All" pythonVersion = "3.11" -typeCheckingMode = "standard" +typeCheckingMode = "all" -reportUntypedFunctionDecorator = "error" -reportUntypedClassDecorator = "error" -reportUntypedNamedTuple = "error" -reportTypeCommentUsage = "error" -reportConstantRedefinition = "error" -reportDeprecated = "warning" -reportIncompatibleMethodOverride = "error" -reportOverlappingOverload = "error" -reportUnnecessaryIsInstance = "error" -reportUnnecessaryCast = "error" -reportUnnecessaryComparison = "error" -reportUnnecessaryContains = "error" -reportUnnecessaryTypeIgnoreComment = "error" -reportImplicitOverride = "error" -reportShadowedImports = "error" +# 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"