Skip to content

Type-check the whole package with pyright or basedpyright #792

Open

Description

@JuroOravec

Citry's users type-check their apps with mypy or with pyright (directly, through Pylance in VS Code, or through basedpyright). Citry's types should work the same in each of them.

Today the gate (scripts/check.py) runs mypy over the Python packages, but runs pyright only on the typing contract tests, such as test_events_typing.py. Checking the whole package with pyright or basedpyright would also catch errors that mypy misses. One example from django-components: a function created inside a loop that refers to the loop variable.

What django-components found when it tried basedpyright:

  • basedpyright's default mode is stricter than pyright's, so the config needs a list of rules to turn off.
  • Pylance and pyright report basedpyright-only rule names as invalid config. And when a pyrightconfig.json file exists, both tools ignore the [tool.basedpyright] or [tool.pyright] section of pyproject.toml completely. So one shared config cannot serve every editor and the gate at once.
  • Most of the errors came from untyped Django code. Citry does not depend on Django, so it should see far fewer.

Running more than one type checker over the same code may also turn up cases where mypy, pyright and basedpyright disagree, which may lead to issues filed upstream in those projects.

Moved from django-components#1397.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions