strawberry
strawberry copied to clipboard
Fix untyped decorator
Closes #1929
Thanks @aryaniyaps for the help!
Summary by Sourcery
Fix typing of field decorators to return StrawberryField and improve type checking support.
Bug Fixes:
- Fix untyped decorator error for @strawberry.field and @strawberry.federation.field by specifying return type as StrawberryField instead of Any.
Enhancements:
- Simplify field function parameter defaults to untyped literals to improve type inference.
- Update mypy test runner to treat empty output as success.
Documentation:
- Document the typing fix in RELEASE.md to explain the untyped decorator issue and its resolution.
Tests:
- Add type-checking tests for fields with arguments to validate mypy and pyright behavior.
Reviewer's Guide
Adjusts type annotations for field decorators to return StrawberryField, streamlines parameter defaults in the decorator signature, enhances the mypy test utility, and adds new type-checking tests along with release notes.
Class Diagram: strawberry.federation.field Decorator Signature Update
classDiagram
class StrawberryField {
<<Type>>
}
class Field_strawberry_federation {
<<Function>>
# strawberry.federation.field()
+field(resolver: Any, name: Optional[str], ..., external: bool, ..., graphql_type: Optional[Any]) : StrawberryField
}
Field_strawberry_federation ..> StrawberryField : returns
File-Level Changes
| Change | Details | Files |
|---|---|---|
| Field decorator overloads now return StrawberryField instead of Any |
|
strawberry/types/field.pystrawberry/federation/field.py |
| Simplified parameter types in field decorator implementation |
|
strawberry/types/field.py |
| Improved mypy runner to handle empty output |
|
tests/typecheckers/utils/mypy.py |
| Added new type-checking tests for field decorators |
|
tests/typecheckers/test_fields_with_arguments.py |
| Documented the patch release in release notes |
|
RELEASE.md |
Assessment against linked issues
| Issue | Objective | Addressed | Explanation |
|---|---|---|---|
| #1929 | Fix the mypy error 'untyped decorator makes function .. untyped' when using @strawberry.field with arguments. |
✅ |
Possibly linked issues
- #1929: The PR modifies type hints for @strawberry.field and adds a test to fix the mypy 'untyped decorator' error when arguments are used.
- #1929: PR changes strawberry.field type hint and adds test to fix mypy untyped decorator error.
Tips and commands
Interacting with Sourcery
- Trigger a new review: Comment
@sourcery-ai reviewon the pull request. - Continue discussions: Reply directly to Sourcery's review comments.
- Generate a GitHub issue from a review comment: Ask Sourcery to create an
issue from a review comment by replying to it. You can also reply to a
review comment with
@sourcery-ai issueto create an issue from it. - Generate a pull request title: Write
@sourcery-aianywhere in the pull request title to generate a title at any time. You can also comment@sourcery-ai titleon the pull request to (re-)generate the title at any time. - Generate a pull request summary: Write
@sourcery-ai summaryanywhere in the pull request body to generate a PR summary at any time exactly where you want it. You can also comment@sourcery-ai summaryon the pull request to (re-)generate the summary at any time. - Generate reviewer's guide: Comment
@sourcery-ai guideon the pull request to (re-)generate the reviewer's guide at any time. - Resolve all Sourcery comments: Comment
@sourcery-ai resolveon the pull request to resolve all Sourcery comments. Useful if you've already addressed all the comments and don't want to see them anymore. - Dismiss all Sourcery reviews: Comment
@sourcery-ai dismisson the pull request to dismiss all existing Sourcery reviews. Especially useful if you want to start fresh with a new review - don't forget to comment@sourcery-ai reviewto trigger a new review!
Customizing Your Experience
Access your dashboard to:
- Enable or disable review features such as the Sourcery-generated pull request summary, the reviewer's guide, and others.
- Change the review language.
- Add, remove or edit custom review instructions.
- Adjust other review settings.
Getting Help
- Contact our support team for questions or feedback.
- Visit our documentation for detailed guides and information.
- Keep in touch with the Sourcery team by following us on X/Twitter, LinkedIn or GitHub.
Apollo Federation Subgraph Compatibility Results
| Federation 1 Support | Federation 2 Support | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
Learn more:
Thanks for adding the RELEASE.md file!

Here's a preview of the changelog:
This release fixes a long standing typing issue where mypy would return the following error:
main:14: error: Untyped decorator makes function "e" untyped [misc] (diff)
When using the following code:
import strawberry
@strawberry.type
class Query:
@strawberry.field(description="Get the last user")
def last_user_v2(self) -> str:
return "Hello"
Here's the tweet text:
🆕 Release (next) is out! Thanks to @patrick91 for the PR 👏
Get it here 👉 https://strawberry.rocks/release/(next)
Codecov Report
Attention: Patch coverage is 50.00000% with 6 lines in your changes missing coverage. Please review.
Project coverage is 95.00%. Comparing base (
1568133) to head (0f0f5b6).
Additional details and impacted files
@@ Coverage Diff @@
## main #3867 +/- ##
==========================================
- Coverage 95.01% 95.00% -0.02%
==========================================
Files 508 509 +1
Lines 33141 33153 +12
Branches 1721 1722 +1
==========================================
+ Hits 31490 31496 +6
- Misses 1370 1376 +6
Partials 281 281
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
CodSpeed Performance Report
Merging #3867 will not alter performance
Comparing fix/mypy-field-typing (0f0f5b6) with main (1568133)
Summary
✅ 21 untouched benchmarks