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(mypy): Fix issue with input and interface pydantic decorators #1832

Merged
merged 2 commits into from
Apr 21, 2022

Conversation

thejaminator
Copy link
Contributor

Resolves #1830

Description

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.
  • [ x] I have added tests to cover my changes.
  • [ x] I have tested the changes and verified that they work and don't break anything (as well as I can manage).

@@ -922,6 +922,7 @@ def _is_strawberry_pydantic_decorator(self, fullname: str) -> bool:
for strawberry_decorator in {
"strawberry.experimental.pydantic.object_type.type",
"strawberry.experimental.pydantic.object_type.input",
"strawberry.experimental.pydantic.object_type.interface",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

i think we forgot to support the interface decorator, so i just added it

@codecov
Copy link

codecov bot commented Apr 21, 2022

Codecov Report

Merging #1832 (5b4bd99) into main (f793f07) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##             main    #1832   +/-   ##
=======================================
  Coverage   98.15%   98.15%           
=======================================
  Files         143      143           
  Lines        5466     5467    +1     
  Branches     1001     1001           
=======================================
+ Hits         5365     5366    +1     
  Misses         50       50           
  Partials       51       51           

@botberry
Copy link
Member

Thanks for adding the RELEASE.md file!

Here's a preview of the changelog:


Fixes mypy type inference when using @strawberry.experimental.pydantic.input
and @strawberry.experimental.pydantic.interface decorators


Here's the preview release card for twitter:

Here's the tweet text:

🆕 Release (next) is out! Thanks to James Chua for the PR 👏

Get it here 👉 https://github.com/strawberry-graphql/strawberry/releases/tag/(next)

directives=directives,
all_fields=all_fields,
use_pydantic_alias=use_pydantic_alias,
)
Copy link
Contributor Author

@thejaminator thejaminator Apr 21, 2022

Choose a reason for hiding this comment

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

technically you could just leave in partial(type, is_input=True) and put this in the IF TYPE_CHECKING block. Anyways i made it like this so that its less confusing when users introspect. they may not be familar to what IF TYPE_CHECKING

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.

Makes sense, do you think we can also add this? https://github.com/strawberry-graphql/strawberry/blob/main/strawberry/object_type.py#L152-L153

this should make it work slightly better with pyright

@thejaminator
Copy link
Contributor Author

thejaminator commented Apr 21, 2022

Makes sense, do you think we can also add this? https://github.com/strawberry-graphql/strawberry/blob/main/strawberry/object_type.py#L152-L153

this should make it work slightly better with pyright

does that work out of the box for the pydantic conversion? not familar with how that works but i think the init for the dataclass wouldn't work well because not all the fields are in the class getting decorated.

e.g.

class UserCreate(BaseModel):
    email: str


@strawberry.experimental.pydantic.input(model=UserCreate, all_fields=True)
class UserCreateInput:
    pass # the fields aren't here

if it doesn't and gives false positives i'll settle it in another issue

@patrick91
Copy link
Member

Makes sense, do you think we can also add this? https://github.com/strawberry-graphql/strawberry/blob/main/strawberry/object_type.py#L152-L153
this should make it work slightly better with pyright

does that work out of the box for the pydantic conversion? not familar with how that works but i think the init for the dataclass wouldn't work well because not all the fields are in the class getting decorated.

e.g.

class UserCreate(BaseModel):
    email: str


@strawberry.experimental.pydantic.input(model=UserCreate, all_fields=True)
class UserCreateInput:
    pass # the fields aren't here

if it doesn't and gives false positives i'll settle it in another issue

it only works with fields that are defined, so yeah, let's do it in another issue :)

@patrick91 patrick91 merged commit 7e93dec into strawberry-graphql:main Apr 21, 2022
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.

mypy errors when using Pydantic integration
3 participants