Skip to content

Add 'strawberry' as a project#157

Merged
sharkdp merged 2 commits intomasterfrom
add-strawberry
Apr 23, 2025
Merged

Add 'strawberry' as a project#157
sharkdp merged 2 commits intomasterfrom
add-strawberry

Conversation

@sharkdp
Copy link
Collaborator

@sharkdp sharkdp commented Apr 22, 2025

When working on @dataclass_transform support, I found it helpful to test on strawberry, as it makes heavy use of the feature.

The projects.py file has a comment on top ("repos with plugins") which lists strawberry. I'm not sure if that entry implies anything regarding using it as a project. But I had to set --config-file= for mypy (as was done for some other projects), because of some errors when trying to run with strawberry's mypy.ini (related to --install-types and --non-interactive).

I tested using mypy, pyright, and Red Knot.

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
@AlexWaygood
Copy link
Collaborator

The projects.py file has a comment on top ("repos with plugins") which lists strawberry. I'm not sure if that entry implies anything regarding using it as a project.

Yes, so we can see in its mypy.ini file that it uses two mypy plugins when mypy is run on the project in CI -- pydantic's mypy plugin, and a second one that comes as part of strawberry itself: https://github.com/strawberry-graphql/strawberry/blob/fc1ab18a3334784e71e178de7063d4fbb90dce55/mypy.ini#L3. If mypy is run on strawberry without those plugins installed and selected, it'll give pretty different results to the results that mypy gives in strawberry's CI. That goes against the general aim of mypy_primer, which is that each project configuration should roughly emulate what happens when that project runs mypy/pyright in CI.

I'm not totally familiar with how mypy_primer handles mypy plugins, and I'm not sure if it's possible to specify mypy plugins without a mypy config file (so specifying --config-file= might get in the way here).

  • set needs_mypy_plugins=True
  • add pydantic as a dependency (so that the pydantic plugin is installed)
  • add something like install_cmd="{install} ." so that strawberry itself is installed (and its mypy plugin with it) before strawberry is type-checked

You can see the django-stubs setup here, which is another project that uses mypy plugins:

Project(
location="https://github.com/typeddjango/django-stubs",
mypy_cmd="{mypy} django-stubs",
pyright_cmd=None,
deps=[
"asgiref",
"django-stubs-ext",
"django",
"redis",
"tomli",
"types-PyYAML",
],
needs_mypy_plugins=True,
expected_success=("mypy",),
install_cmd="{install} . ./ext",
),

Copy link
Owner

@hauntsaninja hauntsaninja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alex is right, but if I remember correctly even after the --install-types --non-interactive issue there was something fiddly with this plugin, so I'm happy to take this PR as is (it preserves the TODO at the top, which is good).

If strawberry is providing useful coverage for knot, it will also provide useful coverage for mypy without plugins

@sharkdp sharkdp merged commit 643d7c9 into master Apr 23, 2025
4 checks passed
@sharkdp sharkdp deleted the add-strawberry branch April 23, 2025 08:46
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.

3 participants