Enable Pyright’s Strict Mode#

For projects using pyright you can enable strict mode for stricter than normal type checking. See the docs for a full breakdown. The primary benefits are increased confidence in code that has been more thoroughly analyzed and a shorter development time thanks to fast feedback from the type checker.

Configuration#

Change the typeCheckingMode line to "strict" in pyproject.toml as follows:

[tool.pyright]
typeCheckingMode = "strict"
reportMissingImports = false # Ignore missing stubs in imported modules

Third Party Libraries#

Strict mode does not usually work well with libraries that do not have type stubs, you will likely need a # type: ignore on any line that directly uses the library code. This may limit the usefulness of pyright but it can still be worth doing to ensure your own code is internally consistent.