-
Notifications
You must be signed in to change notification settings - Fork 767
Enum conversion fixes #665
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
Closed
Closed
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
3f35b1f
cover enum case where choice begins with a number
zbyte64 8d42c7c
chomp out non-ascii characters from enum name generation
zbyte64 1bcc1ef
fix python 2 test regression
zbyte64 5b45c5d
fix python 2 test regression: set source file encoding to utf8
zbyte64 e3017b5
increment version to match release tag
mvanlonden 9275163
test and handle choices that start with an underscore, issue #141
zbyte64 71ba7fb
Merge remote-tracking branch 'up/master' into enum_conversion_fixes
zbyte64 6008e4d
fix unit tests
zbyte64 43233d7
expand test assertions so that test enum conversion with underscores …
zbyte64 59184a1
prefix underscore choice name only if it is dunder, otherwise undersc…
zbyte64 de7edaa
expand test case to cover underscores that are sunder, dunder, and ge…
zbyte64 4ba3b54
Merge remote-tracking branch 'up/master' into enum_conversion_fixes
zbyte64 6d5cfee
apply black formatting
zbyte64 8f354ee
cleanup test choices
zbyte64 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@zbyte64 I'm a bit confused with what is happening here. If the name starts with
_
you're prefixing it with aA
? Why is that?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.
assert_valid_name
requires the name not to start with an_
. Without this, a name like_amount
would be caught andA_
would be prefixed to becomeA__amount
. With this change, the name becomesA_amount
, removing the extra_
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.
@zbyte64 I don't think that is right. Running
assert_valid_name
on a values with both_
and__
work fine:Uh oh!
There was an error while loading. Please reload this page.
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.
Erm, I mispoke.
assert_valid_name
will accept names that start in_
but graphene's Enum will skip over them when populating members. Thus we need to prefix this special case ourselves.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.
Specifically in the code where this happens: https://github.com/graphql-python/graphene/blob/6c7cd4e4fa6e29f55ebf02f173281d46d9f8fc1c/graphene/pyutils/enum.py#L109
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.
I think I see now. I expanded the test case to cover the various underscore mixtures.
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.
How does a normal Python enum handle these sunder and dunder 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.
Creating a python enum with a sunder causes:
ValueError: _names_ are reserved for future Enum use
Dunder is allowed but is ignored (doesn't generate a member).
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.
Then does it make sense to have the same limitations in the Graphene Enum type instead of tacking
A_
on the front?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.
We're already converting choices that wouldn't be allowed, like those that start with a number.