Skip to content

Conversation

@sharkdp
Copy link
Collaborator

@sharkdp sharkdp commented Mar 12, 2025

Thank you for creating mypy_primer! As of recently, we use it to run test Red Knot against (a small subset of) ecosystem projects. So far, we use a fork of mypy_primer, but I would like to clean up our implementation, add some improvements, and potentially upstream some of the changes — if you are interested.

As a first step, I would like to propose a change to the Project dataclass. So far, it stores a custom mypy_cmd and a pyright_cmd. I've noticed that the pyright_cmd in particular only comes in three variants:

  • pyright_cmd=None — which means that Pyright shouldn't run for this project
  • pyright_cmd="{pyright}" — which means that Pyright should be executed without passing any explicit paths
  • pyright_cmd="{pyright} some relative paths" — which means that the command line includes a list of explicit paths that are passed to Pyright.
    In particular, there are no pyright_cmd fields that pass additional flags to pyright.

For running other type checkers, it would be beneficial to have that information in a more structured form. This way we could reuse the list of explicit paths. So I'm proposing the following change:

  • For projects that previously used pyright_cmd=None, we add a new flag pyright_skip=True.
  • For projects that previously used pyright_cmd="{pyright}", we simply remove that pyright_cmd parameter. We consider that to be the new default.
  • For projects that previously used pyright_cmd="{pyright} some relative paths", we also remove the pyright_cmd parameter and add a new paths=["some", "relative", "paths"] field.

I have not attempted to change the representation for mypy, but I could do so if it seems desirable. I'd like to discuss the general approach first.

I tested this by running

mypy_primer --type-checker pyright

@sharkdp sharkdp changed the title Project: use list of paths instead of pyright_cmd Project: use list of paths instead of pyright_cmd Mar 12, 2025
@sharkdp sharkdp force-pushed the project-list-of-paths branch from 143df30 to edc5cc5 Compare March 12, 2025 19:25
hauntsaninja added a commit that referenced this pull request Apr 18, 2025
Supersedes #135

This PR should be a no-op, but I'll also go through the "{pyright}"
cases as well
@hauntsaninja
Copy link
Owner

Sorry for the delay! This has run into some merge conflicts; I fixed up and took a slightly different approach in #151. Let me know what you think!

@sharkdp sharkdp closed this Apr 18, 2025
hauntsaninja added a commit that referenced this pull request Apr 18, 2025
Supersedes #135

This PR should be a no-op, but I'll also go through the "{pyright}"
cases as well
sharkdp added a commit to astral-sh/ruff that referenced this pull request Apr 22, 2025
## Summary

Switch to the official version of
[`mypy_primer`](https://github.com/hauntsaninja/mypy_primer), now that
Red Knot support has been upstreamed (see
hauntsaninja/mypy_primer#138,
hauntsaninja/mypy_primer#135,
hauntsaninja/mypy_primer#151,
hauntsaninja/mypy_primer#155).

## Test Plan

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants