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.
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
Fix _add_enum_value_python_name() to respect explicitly set value names #2073
base: master
Are you sure you want to change the base?
Fix _add_enum_value_python_name() to respect explicitly set value names #2073
Changes from 3 commits
bdaa4ad
877be66
64f00ea
bf0540b
ff725c9
701c364
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
Here you use
hardcoded
as a synonym touser_set
. Reduce ambiguity by using one term to refer to one concept everywhere.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.
FWIW I like the word "explicit" for this. It means (in my mind) that it's there written in metadata.
"User set" is a bit ambiguous because it's not super clear who the user is.
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've stopped using the word hardcoded and made use of the word explicit, instead, as part of my rewrite.
I eliminated the
user_set_python_name
key. We'll do processing on the temporary key,'_python_name'
, instead, so we won't need a special key to track whether we should expand the name.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.
Strangely, (with the codegen helper changes) if I set
python_name
for all the values except this one, this one came back asTEMP
. I'm not sure why it gets cut off like that, but didn't feel it was worth further investigation.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.
Does that mean that if a client wants to explicitly provide the python name for a subset of enum values, we don't know what will be the expanded value here?
I feel like it's worth getting to the bottom of, and having a test case for.
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.
It was almost certainly due to common suffix removal.
The behavior was a little bit hard to follow, so I've rewritten my change and instead of using a boolean key for tracking whether to touch something, I'll have us do all of the processsing with a temporary key, '_python_name'.
I've also added another unit test enum related to this. There's a peculiar behavior with common prefix and common suffix removal when you only have one value to calculate the prefix or suffix from. It calculates the prefix or suffix as the entire string and we then remove almost that entire string (upto and including the first/last underscore). I setting prefix and suffix to '', instead, when there's less than 2 values to calculate the commmon prefix or suffix from, but (upsetting as it is) we have one or two enums with a single enum value that actually make use of this behavior. I can still change it if you want, though. It seems like a footgun.
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.
With the latest change, we no longer need to set 'python_name': 'CUSTOM', but this behavior still seems like a footgun.
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.
If the behavior observed when only a subset of the enum values has
python_name
explicitly in metadata is hard to describle / footgun, we could consider disallowing this altogether and forcing clients to specify none or all. I think the case is rare enough that there would be very few cases of this.Counterpoint is that bad expansion of a subset of enum values should be fairly apparent in generated code diffs.
What do you think?
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.
It's easy to describe at this point. Everything up through the last underscore is trimmed. This is the same behavior we would see if the values that use
python_name
didn't exist.You're correct that is very rare and even rarer is the case where we have an enum with only one value and the one value has multiple words and that enum is used somewhere so we don't filter it out in codegen. We only seem to have a couple of those and the current value names seem okay.
I think it's fine to leave this change as is. We should be able to catch any issues in review.
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.
Yeah, that's another option. Wouldn't be too difficult to do, though I'm not sure how easy it is to test.