Skip to content

Conversation

patrick91
Copy link
Member

@patrick91 patrick91 commented Sep 22, 2025

  • WIP
  • WIP

Summary by Sourcery

Enable support for using Annotated to define GraphQL fields by decoupling StrawberryField from dataclasses.Field and converting them into real dataclass fields during type wrapping.

New Features:

  • Add StrawberryDataclassField for converting StrawberryField instances into dataclasses.Field representations
  • Introduce _convert_field_annotations_to_dataclass_fields to process annotated fields on object types

Enhancements:

  • Refactor StrawberryField to no longer subclass dataclasses.Field and store default, default_factory, and metadata directly
  • Integrate annotated field conversion into the object type wrapping workflow
  • Remove redundant type ignore comments and simplify generic checks in typing and info modules

Copy link
Contributor

sourcery-ai bot commented Sep 22, 2025

Reviewer's Guide

This PR refactors how StrawberryField integrates with Python dataclasses by decoupling it from dataclasses.Field, introduces a dedicated StrawberryDataclassField wrapper with conversion logic, injects an automated conversion step for annotated fields in object types, and cleans up minor typings and utility functions.

File-Level Changes

Change Details Files
Decouple StrawberryField from dataclasses.Field
  • Removed subclassing of dataclasses.Field
  • Dropped super().init invocation and related init arguments
  • Added internal attributes: default, default_factory, metadata, name
strawberry/types/field.py
Add StrawberryDataclassField for wrapping StrawberryField
  • Created new class extending dataclasses.Field
  • Stored original StrawberryField reference internally
  • Implemented from_strawberry_field factory method
strawberry/types/_dataclasses_field.py
Automate conversion of StrawberryField annotations into dataclass fields
  • Introduced _convert_field_annotations_to_dataclass_fields helper
  • Updated wrap logic to call helper instead of manual iteration
  • Removed outdated original_type_annotations handling
strawberry/types/object_type.py
Clean up typing utilities and info subclassing
  • Removed unnecessary type ignore comments
  • Simplified issubclass checks in generic helpers
  • Adjusted tuple assignment without type ignores in Info.class_getitem
strawberry/utils/typing.py
strawberry/types/info.py

Possibly linked issues

  • #0: The PR refactors StrawberryField by introducing StrawberryDataclassField which inherits from dataclasses.Field, resolving the mypy type incompatibility issue for strawberry.field.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on 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 issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on 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 dismiss on 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 review to 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

Copy link
Contributor

codeflash-ai bot commented Sep 22, 2025

⚡️ Codeflash found optimizations for this PR

📄 12% (0.12x) speedup for Info.__class_getitem__ in strawberry/types/info.py

⏱️ Runtime : 105 microseconds 94.4 microseconds (best of 90 runs)

I created a new dependent PR with the suggested changes. Please review:

If you approve, it will be merged into this PR (branch feature/annotated).

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.

1 participant