Skip to content

Conversation

Ckk3
Copy link
Collaborator

@Ckk3 Ckk3 commented Sep 22, 2025

Description

Replace EnumDefinition with StrawberryEnum

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).

Summary by Sourcery

Replace the legacy EnumDefinition with StrawberryEnum throughout the core codebase, ensuring all conversions, codegen paths, and tests are updated to use the new class name.

Enhancements:

  • Replace all occurrences of the deprecated EnumDefinition class with the new StrawberryEnum type across schema conversion, name conversion, code generation, federation, and experimental Pydantic modules
  • Update method signatures, type checks, and imports to reference StrawberryEnum instead of EnumDefinition
  • Refactor tests to assert against StrawberryEnum and adjust related imports

Documentation:

  • Add a patch release note in RELEASE.md documenting the renaming of EnumDefinition to StrawberryEnum

Copy link
Contributor

sourcery-ai bot commented Sep 22, 2025

Reviewer's Guide

This PR fully replaces the deprecated EnumDefinition with the newly named StrawberryEnum across the entire codebase by renaming the core class, updating exports, refactoring imports, type hints, isinstance checks, and aligning tests accordingly.

File-Level Changes

Change Details Files
Rename EnumDefinition to StrawberryEnum in enum definition module and exports
  • Rename the EnumDefinition class to StrawberryEnum
  • Update the all export list to include StrawberryEnum
  • Add a RELEASE.md entry documenting the change
strawberry/types/enum.py
RELEASE.md
Refactor core modules to reference StrawberryEnum
  • Update all import statements to pull StrawberryEnum instead of EnumDefinition
  • Change function signatures and type hints from EnumDefinition to StrawberryEnum
  • Replace isinstance checks and remove related TODO comments
strawberry/schema/schema_converter.py
strawberry/schema/name_converter.py
strawberry/schema/schema.py
strawberry/types/arguments.py
strawberry/annotation.py
strawberry/codegen/query_codegen.py
strawberry/experimental/pydantic/conversion.py
strawberry/federation/schema.py
strawberry/schema/base.py
strawberry/schema/types/concrete_type.py
strawberry/printer/printer.py
strawberry/types/base.py
Align test suite with StrawberryEnum
  • Update test imports to reference StrawberryEnum
  • Adjust isinstance assertions to check for StrawberryEnum
tests/enums/test_enum.py
tests/schema/test_name_converter.py
tests/experimental/pydantic/test_basic.py
tests/objects/generics/test_names.py
tests/types/resolving/test_generics.py

Assessment against linked issues

Issue Objective Addressed Explanation
#3998 Replace all uses of EnumDefinition with StrawberryEnum in the codebase, specifically resolving the TODOs at lines 872 and 885 in strawberry/schema/schema_converter.py.

Possibly linked issues


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

codecov bot commented Sep 22, 2025

Codecov Report

❌ Patch coverage is 96.39640% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.25%. Comparing base (0bdfea4) to head (9bad777).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3999      +/-   ##
==========================================
+ Coverage   94.24%   94.25%   +0.01%     
==========================================
  Files         531      532       +1     
  Lines       34829    34876      +47     
  Branches     1847     1847              
==========================================
+ Hits        32824    32872      +48     
  Misses       1700     1700              
+ Partials      305      304       -1     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

codspeed-hq bot commented Sep 22, 2025

CodSpeed Performance Report

Merging #3999 will create unknown performance changes

Comparing Ckk3:issue-3998 (9bad777) with main (e79d1cb)

Summary

⚠️ No benchmarks were detected in both the base of the PR and the PR.
Please ensure that your benchmarks are correctly instrumented with CodSpeed.

Check out the benchmarks creation guide
⏩ 27 skipped1

Footnotes

  1. 27 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@Ckk3 Ckk3 marked this pull request as ready for review September 22, 2025 19:51
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 there - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `RELEASE.md:3` </location>
<code_context>
+Release type: patch
+
+Resolve TODO's about EnumDefinition by renaming it to StrawberryEnum
</code_context>

<issue_to_address>
**suggestion (typo):** Consider changing "TODO's" to "TODOs" for correct pluralization.

The correct plural is "TODOs" without the apostrophe.
</issue_to_address>

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 and I'll use the feedback to improve your reviews.

@botberry
Copy link
Member

botberry commented Sep 22, 2025

Thanks for adding the RELEASE.md file!

Here's a preview of the changelog:


Deprecation Alert

  • Deprecated: Replaced _enum_definition with __strawberry_definition__. The former will continue to work but will raise a deprecation warning.

Other Changes

  • Renamed: Changed EnumDefinition to StrawberryEnum to standardize internal naming patterns.
  • These updates improve naming consistency and address previously identified TODOs.

Here's the tweet text:

🆕 Release (next) is out! Thanks to Luis Gustavo for the PR 👏

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

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Greptile Summary

This PR performs a systematic codebase-wide refactoring that renames the EnumDefinition class to StrawberryEnum and updates all references throughout the Strawberry GraphQL library. The change affects 17 files across core modules, tests, and integrations, resolving existing TODO comments that had explicitly marked this renaming as planned technical debt.

The refactoring touches several key areas of the codebase:

  • Core enum handling: The main enum class in strawberry/types/enum.py is renamed from EnumDefinition to StrawberryEnum, with the __all__ export list updated accordingly
  • Schema system: Updates to schema converters, name converters, and type checking logic to use the new class name
  • Code generation: Query codegen and federation modules updated to properly handle the renamed enum type
  • Type system: Updates to argument handling, annotation processing, and printer logic
  • Integrations: Pydantic integration updated to work with the new enum class name
  • Test suite: Comprehensive updates to test assertions and mock object creation

The change maintains complete backward compatibility since StrawberryEnum provides the identical interface and functionality as EnumDefinition. The renaming aligns with Strawberry's naming conventions where core types are prefixed with 'Strawberry' (similar to StrawberryType, StrawberryUnion, etc.). All functionality remains exactly the same - this is purely a naming standardization effort that removes deprecated references and improves code consistency across the library.

Confidence score: 5/5

  • This PR is extremely safe to merge with no risk of breaking functionality
  • Score reflects that this is a systematic renaming with identical interfaces and comprehensive coverage across all affected files
  • No files require special attention as the changes are mechanical and maintain exact same behavior

19 files reviewed, no comments

Edit Code Review Bot Settings | Greptile

values.append(value)

cls._enum_definition = EnumDefinition( # type: ignore
cls.__strawberry_definition__ = StrawberryEnum( # type: ignore
Copy link
Member

Choose a reason for hiding this comment

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

should we also keep a deprecated ._enum_definiton for compatibility?

You can use this DeprecatedDescriptor, like we have for the old _type_definition

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agree, I'll do it!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated!


@dataclasses.dataclass
class EnumDefinition(StrawberryType):
class StrawberryEnum(StrawberryType):
Copy link
Member

Choose a reason for hiding this comment

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

Like my comment below, we also need to expose the deprecated version of this

Like in https://github.com/strawberry-graphql/strawberry/blob/main/strawberry/types/base.py#L456-L456

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree, updating now!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated, @bellini666 , I use the same implementation we done in this PR #2836 .
Please let me now if you see a better way to do it!

RELEASE.md Outdated
@@ -0,0 +1,3 @@
Release type: patch
Copy link
Member

Choose a reason for hiding this comment

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

Would this be a minor? It does more than just fixing, it also changes variable names

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree 100% with you, also will add a deprecated info on the release

@Ckk3
Copy link
Collaborator Author

Ckk3 commented Sep 28, 2025

Already fixing this CI errors.

@Ckk3
Copy link
Collaborator Author

Ckk3 commented Sep 28, 2025

Ready to review @bellini666

@Ckk3 Ckk3 requested a review from bellini666 September 28, 2025 20:50
@Ckk3 Ckk3 self-assigned this Oct 17, 2025
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.

Resolve TODO: Replace with StrawberryEnum

3 participants