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

Summary by Sourcery

Migrate all enum-related logic to use the new StrawberryEnum class, remove the legacy EnumDefinition, and introduce deprecation aliases and warnings for backward compatibility

Enhancements:

  • Rename internal enum definition class from EnumDefinition to StrawberryEnum across the core codebase
  • Deprecate legacy _enum_definition attribute with a backward-compatible alias and deprecation warnings
  • Update schema conversion, codegen, federation, annotation, name converter, and compatibility logic to use StrawberryEnum

Documentation:

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

Tests:

  • Refactor tests to reference StrawberryEnum and assert deprecation warnings for the old enum definition

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Sep 22, 2025

Reviewer's Guide

This PR systematically replaces the legacy EnumDefinition class and related _enum_definition attributes with the new StrawberryEnum construct, updating all core schema conversion paths, type checks, code generation, and tests to reference StrawberryEnum and strawberry_definition, while preserving backward compatibility through deprecation aliases and warnings.

File-Level Changes

Change Details Files
Rename legacy EnumDefinition class to StrawberryEnum
  • Renamed class declaration and wrapped_cls field in enum core module
  • Updated all exports to include StrawberryEnum
  • Added TYPE_CHECKING alias for deprecated EnumDefinition
strawberry/types/enum.py
Replace type checks and imports to use StrawberryEnum
  • Replaced isinstance and import of EnumDefinition with StrawberryEnum in schema_converter and name_converter
  • Updated compat, arguments, annotation, federation, codegen, printer, and base modules to reference StrawberryEnum
  • Switched attribute access from _enum_definition to strawberry_definition
strawberry/schema/schema_converter.py
strawberry/schema/name_converter.py
strawberry/schema/compat.py
strawberry/types/arguments.py
strawberry/annotation.py
strawberry/federation/schema.py
strawberry/schema/base.py
strawberry/schema/types/concrete_type.py
strawberry/codegen/query_codegen.py
strawberry/experimental/pydantic/conversion.py
strawberry/printer/printer.py
Add deprecation support for _enum_definition attribute
  • Injected DeprecatedDescriptor to alias _enum_definition to strawberry_definition with warning
  • Added _ENUM_DEFINITION message in DEPRECATION_MESSAGES
strawberry/types/enum.py
strawberry/utils/deprecations.py
Refactor tests to assert and import StrawberryEnum over EnumDefinition
  • Updated deprecation tests to expect _enum_definition warnings on Color enum
  • Replaced all EnumDefinition imports and assertions with StrawberryEnum across tests
tests/test_deprecations.py
tests/enums/test_enum.py
tests/schema/test_extensions.py
tests/schema/test_name_converter.py
tests/types/resolving/test_generics.py
tests/types/test_argument_types.py
tests/types/test_field_types.py
tests/types/test_object_types.py
tests/types/test_resolver_types.py
tests/experimental/pydantic/test_basic.py
tests/objects/generics/test_names.py
tests/types/resolving/test_enums.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.
#3998 Ensure that references to _enum_definition are deprecated in favor of strawberry_definition, with appropriate warnings and backwards compatibility.

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

@codecov
Copy link

codecov bot commented Sep 22, 2025

Codecov Report

❌ Patch coverage is 97.67442% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.39%. Comparing base (abbe4c2) to head (ac2fbdb).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3999   +/-   ##
=======================================
  Coverage   94.39%   94.39%           
=======================================
  Files         534      534           
  Lines       34834    34856   +22     
  Branches     1831     1831           
=======================================
+ Hits        32881    32904   +23     
  Misses       1657     1657           
+ Partials      296      295    -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.

@codspeed-hq
Copy link

codspeed-hq bot commented Sep 22, 2025

CodSpeed Performance Report

Merging #3999 will not alter performance

Comparing Ckk3:issue-3998 (ac2fbdb) with main (abbe4c2)

Summary

✅ 28 untouched

@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
@Ckk3 Ckk3 marked this pull request as ready for review October 27, 2025 02:04
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!


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.

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 Overview

Greptile Summary

This PR successfully completes a systematic refactoring that renames EnumDefinition to StrawberryEnum throughout the codebase, resolving TODOs in strawberry/schema/schema_converter.py at lines 872 and 885.

Key Changes

  • Core renaming: EnumDefinition class renamed to StrawberryEnum in strawberry/types/enum.py
  • Attribute migration: All enum definitions now use __strawberry_definition__ instead of _enum_definition
  • Backward compatibility: Old _enum_definition attribute maintained via DeprecatedDescriptor with warnings
  • Type alias: EnumDefinition preserved as a deprecated alias to StrawberryEnum for imports
  • Comprehensive updates: All type hints, imports, and isinstance checks updated across 28 files
  • Updated TODO comments: Removed resolved TODO comments from schema converter

Impact

  • Standardizes naming convention to match other Strawberry types (e.g., StrawberryObjectDefinition)
  • Maintains full backward compatibility with existing code
  • All tests updated to use new patterns
  • Documentation added in RELEASE.md

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The refactoring is comprehensive, systematic, and includes excellent backward compatibility. The deprecated descriptor pattern ensures existing code continues working while warning users. All 28 files are consistently updated, tests are thorough, and the changes follow established patterns in the codebase.
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
strawberry/types/enum.py 5/5 Renamed EnumDefinition to StrawberryEnum, added deprecation support for _enum_definition, and created backward compatibility alias
strawberry/schema/schema_converter.py 5/5 Updated all references from EnumDefinition to StrawberryEnum and resolved TODO comments
strawberry/schema/compat.py 5/5 Updated is_enum() function to check for StrawberryEnum using __strawberry_definition__ attribute
strawberry/types/base.py 5/5 Updated type checking logic to use StrawberryEnum and __strawberry_definition__ instead of _enum_definition
strawberry/utils/deprecations.py 5/5 Added _ENUM_DEFINITION deprecation message for backward compatibility
tests/test_deprecations.py 5/5 Added comprehensive tests for _enum_definition deprecation and EnumDefinition alias
strawberry/types/arguments.py 5/5 Replaced EnumDefinition imports and type checks with StrawberryEnum, updated __strawberry_definition__ usage
RELEASE.md 5/5 Added release notes documenting the EnumDefinition to StrawberryEnum rename and deprecation

Sequence Diagram

sequenceDiagram
    participant Dev as Developer
    participant Enum as @strawberry.enum
    participant Process as _process_enum()
    participant Def as StrawberryEnum
    participant Depr as DeprecatedDescriptor
    participant Code as User Code

    Dev->>Enum: Decorates Enum class
    Enum->>Process: _process_enum(cls)
    Process->>Def: Create StrawberryEnum instance
    Process->>Code: Set cls.__strawberry_definition__
    Process->>Depr: Create DeprecatedDescriptor
    Depr->>Code: Inject _enum_definition property
    
    Note over Code,Depr: New pattern (recommended)
    Code->>Def: Access via __strawberry_definition__
    Def-->>Code: Returns StrawberryEnum
    
    Note over Code,Depr: Old pattern (deprecated)
    Code->>Depr: Access via _enum_definition
    Depr->>Depr: Emit deprecation warning
    Depr-->>Code: Returns same StrawberryEnum

    Note over Dev,Code: Type checking in schema conversion
    Code->>Code: isinstance(type_, StrawberryEnum)
    Code->>Code: type_.__strawberry_definition__
Loading

28 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@Ckk3
Copy link
Collaborator Author

Ckk3 commented Oct 27, 2025

Ready for review again @bellini666
I've finally fixed the CI 😅

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