-
-
Notifications
You must be signed in to change notification settings - Fork 568
feat(parent): Support strawberry.Parent with future annotations #3851
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
Conversation
Reviewer's GuideThis pull request enables File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Summary
Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here: https://app.greptile.com/review/github.
💡 (3/5) Reply to the bot's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!
7 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings | Greptile
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces support for using strawberry.Parent with future annotations, addressing a previously reported issue and simplifying related annotation handling.
- Added tests for both direct and string-based forward references using strawberry.Parent.
- Updated type evaluation and resolver logic to gracefully handle strawberry.Parent types.
- Introduced a new helper function resolve_parent_forward_arg in strawberry/parent.py.
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
tests/types/test_parent_type_future_annotations.py | Adds a test using future annotations with strawberry.Parent (e.g. Parent[User]). |
tests/types/test_parent_type.py | Adds a test using string-based forward references with strawberry.Parent (e.g. Parent["User"]). |
strawberry/utils/typing.py | Updates eval_type to handle StrawberryParent types by checking for instances and adjusting args. |
strawberry/types/fields/resolver.py | Modifies forward reference evaluation to use resolve_parent_forward_arg when a NameError occurs. |
strawberry/types/field.py | Refactors argument type evaluation to catch NameError and skip forward references. |
strawberry/parent.py | Adds the helper function resolve_parent_forward_arg to support parsing strawberry.Parent annotations. |
RELEASE.md | Updates release notes detailing support for strawberry.Parent with both future annotations and delayed evaluation. |
6e2d70a
to
e75995b
Compare
Thanks for adding the Here's a preview of the changelog: This release adds support to use For example, the following code will now work as intended: from __future__ import annotations
def get_full_name(user: strawberry.Parent[User]) -> str:
return f"{user.first_name} {user.last_name}"
@strawberry.type
class User:
first_name: str
last_name: str
full_name: str = strawberry.field(resolver=get_full_name)
@strawberry.type
class Query:
@strawberry.field
def user(self) -> User:
return User(first_name="John", last_name="Doe")
schema = strawberry.Schema(query=Query) Or even when not using future annotations, but delaying the evaluation of # Note the User being delayed by passing it as a string
def get_full_name(user: strawberry.Parent["User"]) -> str:
return f"{user.first_name} {user.last_name}"
@strawberry.type
class User:
first_name: str
last_name: str
full_name: str = strawberry.field(resolver=get_full_name)
@strawberry.type
class Query:
@strawberry.field
def user(self) -> User:
return User(first_name="John", last_name="Doe")
schema = strawberry.Schema(query=Query) Here's the tweet text:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We encountered an error and are unable to review this PR. We have been notified and are working to fix it.
You can try again by commenting this pull request with @sourcery-ai review
, or contact us for help.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3851 +/- ##
========================================
Coverage 95.04% 95.05%
========================================
Files 502 507 +5
Lines 32719 32931 +212
Branches 1696 1710 +14
========================================
+ Hits 31098 31302 +204
- Misses 1348 1355 +7
- Partials 273 274 +1 🚀 New features to boost your workflow:
|
e75995b
to
b497961
Compare
CodSpeed Performance ReportMerging #3851 will not alter performanceComparing Summary
|
b497961
to
d2abf06
Compare
Fix #3481
This also makes #3714 not required
Summary by Sourcery
Add support for using
strawberry.Parent
with future annotations and delayed type evaluationNew Features:
Enhancements:
Tests:
Chores: