Skip to content

Commit

Permalink
Refactor enum implementation in test_enum.py and fix strawberry_enum …
Browse files Browse the repository at this point in the history
…usage in StrawberryAnnotation
  • Loading branch information
nrbnlulu committed Sep 23, 2024
1 parent 73ce325 commit 764988e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion strawberry/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def create_enum(self, evaled_type: Any) -> EnumDefinition:
try:
return evaled_type._enum_definition
except AttributeError:
return strawberry_enum(evaled_type)
return strawberry_enum(evaled_type)._enum_definition

def create_list(self, evaled_type: Any) -> StrawberryList:
item_type, *_ = get_args(evaled_type)
Expand Down
15 changes: 15 additions & 0 deletions tests/enums/test_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from strawberry.exceptions import ObjectIsNotAnEnumError
from strawberry.types.enum import EnumDefinition

from strawberry.types.base import get_object_definition


def test_basic_enum():
@strawberry.enum
Expand Down Expand Up @@ -203,3 +205,16 @@ def foo(self, foo: Foo) -> int:
assert not res.errors
assert res.data
assert res.data["foo"] == 1

def test_default_enum_reuse() -> None:
class Foo(Enum):
BAR = "bar"
BAZ = "baz"

@strawberry.type
class SomeType:
foo: Foo
bar: Foo

definition = get_object_definition(SomeType, strict=True)
assert definition.fields[1].type is definition.fields[1].type

0 comments on commit 764988e

Please sign in to comment.