Compare commits

...

2 commits

Author SHA1 Message Date
ItsDrike 97f7f5da2a
Move to a much stricter pyright configuration
Some checks are pending
CI / validation (push) Waiting to run
CI / unit-tests (push) Waiting to run
CI / Produce Pull Request payload artifact (push) Waiting to run
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.
2024-07-13 13:01:45 +02:00
ItsDrike 0855c6fbb3
basedpyright: Treat warnings as errors 2024-07-13 12:59:17 +02:00
3 changed files with 33 additions and 24 deletions

View file

@ -46,4 +46,4 @@ jobs:
run: slotscheck -m mcproto run: slotscheck -m mcproto
- name: Run basedpyright type checker - name: Run basedpyright type checker
run: basedpyright . run: basedpyright --warnings .

View file

@ -36,9 +36,9 @@ repos:
- repo: local - repo: local
hooks: hooks:
- id: basedpyright - id: basedpyright
name: BasedPyright name: Based Pyright
description: Run BasedPyright type checker description: Run basedpyright type checker
entry: poetry run basedpyright entry: poetry run basedpyright --warnings
language: system language: system
types: [python] types: [python]
pass_filenames: false # pyright runs for the entire project, it can't run for single files pass_filenames: false # pyright runs for the entire project, it can't run for single files

View file

@ -69,8 +69,6 @@ ignore = [
"D416", # Section name should end with a colon "D416", # Section name should end with a colon
"D417", # Missing argument descrition in the docstring "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 "ANN101", # Missing type annotation for self in method
"ANN102", # Missing type annotation for cls in classmethod "ANN102", # Missing type annotation for cls in classmethod
"ANN204", # Missing return type annotation for special method "ANN204", # Missing return type annotation for special method
@ -131,25 +129,36 @@ max-statements = 250
[tool.ruff.format] [tool.ruff.format]
line-ending = "lf" line-ending = "lf"
[tool.pyright] [tool.basedpyright]
pythonPlatform = "All"
pythonVersion = "3.11" pythonVersion = "3.11"
typeCheckingMode = "standard" typeCheckingMode = "all"
reportUntypedFunctionDecorator = "error" # Diagnostic behavior settings
reportUntypedClassDecorator = "error" strictListInference = false
reportUntypedNamedTuple = "error" strictDictionaryInference = false
reportTypeCommentUsage = "error" strictSetInference = false
reportConstantRedefinition = "error" analyzeUnannotatedFunctions = true
reportDeprecated = "warning" strictParameterNoneValue = true
reportIncompatibleMethodOverride = "error" enableTypeIgnoreComments = true
reportOverlappingOverload = "error" deprecateTypingAliases = true
reportUnnecessaryIsInstance = "error" enableExperimentalFeatures = false
reportUnnecessaryCast = "error" disableBytesTypePromotions = true
reportUnnecessaryComparison = "error"
reportUnnecessaryContains = "error" # Diagnostic rules
reportUnnecessaryTypeIgnoreComment = "error" reportAny = false
reportImplicitOverride = "error" reportImplicitStringConcatenation = false
reportShadowedImports = "error" 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] [tool.pytest.ini_options]
minversion = "6.0" minversion = "6.0"
@ -204,7 +213,7 @@ cmd = "pytest -v --failed-first"
help = "Run pytest tests" help = "Run pytest tests"
[tool.poe.tasks.pyright] [tool.poe.tasks.pyright]
cmd = "basedpyright ." cmd = "basedpyright --warnings ."
help = "Run BasedPyright type-checker" help = "Run BasedPyright type-checker"
[tool.poe.tasks.retest] [tool.poe.tasks.retest]