Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix support for pydantic 2.8.0's mypy plugin #3562

Merged

Conversation

lindycoder
Copy link
Contributor

@lindycoder lindycoder commented Jul 8, 2024

Description

Pydantic added a new field to better support generic's variance. It default to False for now based on pydantic's default value for the caller of to_argument.

It's unclear if this is needed in the context of graphql schemas where there shouldn't really be frozensets.

Please let know if I can improve this.

Types of Changes

  • Core
  • Bugfix
  • New feature
  • Enhancement/optimization
  • Documentation

Issues Fixed or Closed by This PR

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • I have tested the changes and verified that they work and don't break anything (as well as I can manage).

I don't know if there are more ways to test, previous change to support 2.7.0 did not seem to have any test change other than the version in the noxfile, to which I added 2.8.0.

Summary by Sourcery

This pull request fixes compatibility issues with Pydantic 2.8.0's mypy plugin by adding necessary fields and updates the test configuration to include Pydantic 2.8.0.

  • Bug Fixes:
    • Added support for Pydantic 2.8.0's mypy plugin by including the 'force_typevars_invariant' field with a default value of False.
  • Tests:
    • Updated the noxfile to include Pydantic 2.8.0 in the test matrix for Pydantic tests.

Pydantic added a new field to better support generic's
variance.  It default to False for now based on pydantic's
default value for the caller of to_argument.

It's unclear if this is needed in the context of graphql
schemas where there shouldn't really be frozensets.
@lindycoder lindycoder marked this pull request as ready for review July 8, 2024 16:39
Copy link
Contributor

sourcery-ai bot commented Jul 8, 2024

Reviewer's Guide by Sourcery

This pull request updates the mypy plugin to support pydantic version 2.8.0 by adding a new field 'force_typevars_invariant' with a default value of False. It also includes tests for pydantic 2.8.0 in the noxfile to ensure compatibility.

File-Level Changes

Files Changes
strawberry/ext/mypy_plugin.py
noxfile.py
Updated the mypy plugin to support pydantic version 2.8.0 by adding a new field 'force_typevars_invariant' and included tests for pydantic 2.8.0 in the noxfile.

Tips
  • Trigger a new Sourcery review by commenting @sourcery-ai review on the pull request.
  • Continue your discussion with Sourcery by replying directly to review comments.
  • You can change your review settings at any time by accessing your dashboard:
    • Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
    • Change the review language;
  • You can always contact us if you have any questions or feedback.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @lindycoder - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

@@ -472,8 +472,13 @@ def strawberry_pydantic_class_callback(ctx: ClassDefContext) -> None:
else:
extra = {}

if PYDANTIC_VERSION and PYDANTIC_VERSION >= (2, 7, 0):
extra["api"] = ctx.api
if PYDANTIC_VERSION:
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Nested conditionals could be simplified.

The nested conditionals checking PYDANTIC_VERSION can be simplified by combining the conditions into a single if statement. This would improve readability.

Suggested change
if PYDANTIC_VERSION:
if PYDANTIC_VERSION and PYDANTIC_VERSION >= (2, 7, 0):
extra["api"] = ctx.api

@botberry
Copy link
Member

botberry commented Jul 8, 2024

Thanks for adding the RELEASE.md file!

Here's a preview of the changelog:


This release ensures using pydantic 2.8.0 doesn't break when using experimental
pydantic_type and running mypy.

Here's the tweet text:

🆕 Release (next) is out! Thanks to Martin Roy for the PR 👏

This release adds support for Pydantic 2.8.0 Mypy plugin.

Get it here 👉 https://strawberry.rocks/release/(next)

Copy link
Member

@patrick91 patrick91 left a comment

Choose a reason for hiding this comment

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

Nice! Thank you, sorry it took so long to review 😊

@patrick91 patrick91 enabled auto-merge (squash) July 24, 2024 10:36
@patrick91 patrick91 merged commit 381bae7 into strawberry-graphql:main Jul 24, 2024
66 checks passed
@botberry
Copy link
Member

Thanks for contributing to Strawberry! 🎉 You've been invited to join
the Strawberry GraphQL organisation 😊

You can also request a free sticker by filling this form: https://forms.gle/dmnfQUPoY5gZbVT67

And don't forget to join our discord server: https://strawberry.rocks/discord 🔥

Copy link

codspeed-hq bot commented Jul 24, 2024

CodSpeed Performance Report

Merging #3562 will not alter performance

Comparing lindycoder:3560-support-pydantic-2.8 (61f6156) with main (581f508)

Summary

✅ 13 untouched benchmarks

@lindycoder lindycoder deleted the 3560-support-pydantic-2.8 branch August 8, 2024 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

strawberry.ext.mypy_plugin Pydantic 2.8 PydanticModelField.to_argument error 'force_typevars_invariant'
3 participants