-
Notifications
You must be signed in to change notification settings - Fork 829
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make Graphene enums iterable like Python enums #1473
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Thanks for the PR! Will test it locally this afternoon and it should be good to merge afterwards! 🙂 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thank you!
Added a small comment suggesting a slight improvment. Should be good to merge afterwards 🙂
graphene/tests/issues/test_1264.py
Outdated
from graphene.types.enum import Enum | ||
|
||
|
||
def test_enum_iteration(): | ||
class TestEnum(Enum): | ||
FIRST = 1 | ||
SECOND = 2 | ||
|
||
result = [] | ||
expected_values = ["FIRST", "SECOND"] | ||
for c in TestEnum: | ||
result.append(c.name) | ||
assert result == expected_values |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be better-placed in test_enum.py
, as this is not really a bug but rather a new "Feature" of the graphene-style enums.
Can you also add this test case for the instance-creation style of enums?
def test_iterable_instance_creation_enum():
TestEnum = Enum("TestEnum", [("FIRST", 1), ("SECOND", 2)])
result = []
expected_values = ["FIRST", "SECOND"]
for c in TestEnum:
result.append(c.name)
assert result == expected_values
58103af
to
ca64b51
Compare
Thank you for the PRs! |
Since Python enums are iterable, the expectation exists that Graphene enums are similarly iterable, as shown in #1264. The proposed solution is to do a straightforward pass-through of the underlying Python enum, so that it will behave exactly the same way.
Fixes #1264