-
Notifications
You must be signed in to change notification settings - Fork 101
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
Clean up dynamic code generation in prep for extension namespacing #302
Conversation
7d8247e
to
133207b
Compare
if field.repeated? | ||
if value.is_a?(Array) | ||
value = value.dup | ||
value.compact! |
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 know this is preserving existing behavior, but just want to note that IMO this compact
thing is super weird behavior, settings an array with nil values in there should def be an error
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 you're going to keep compact!
, you should remove the dup
and just do value = value.compact
. You can drop an array iteration that way and get the same behavior.
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.
Good call. Note though: We copied the code over with minimal changes. No objection to cleaning as we go though.
Should we add a test that verified that the fully qualified names are properly used as keys in |
when optional? then typed_default_value | ||
when repeated? then ::Protobuf::Field::FieldArray.new(self).freeze | ||
when required? then nil | ||
@default_value ||= if optional? || required? |
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.
Isn't adding required?
unnecessary because required?
should always have a value.
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.
lol, ya, but protoc allows default values on required fields, sooooo... we should handle it?
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.
lol welp
re: #302 (comment) We don't yet actually use fully qualified names, but there's a PR incoming where we will add a test for it |
133207b
to
b0f62ba
Compare
elsif repeated? | ||
::Protobuf::Field::FieldArray.new(self).freeze | ||
else | ||
fail "something went very wrong" |
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.
maybe something like "unable to produce default value" or something? very ominous message
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.
Well this code should be unreachable actually, so it should be ominous -- it means a field isn't optional, required, or repeated. We could make change the message though to still be ominous while more descriptive :)
065400e
to
49412d1
Compare
All comments are addressed, interested in review by someone with write access to the repo :) |
49412d1
to
3176340
Compare
3176340
to
10c3ea1
Compare
10c3ea1
to
4b85f47
Compare
4b85f47
to
10c3ea1
Compare
10c3ea1
to
1ceee2f
Compare
@@ -122,10 +124,10 @@ def required? | |||
|
|||
# FIXME: need to cleanup (rename) this warthog of a method. | |||
def set(message_instance, bytes) | |||
return message_instance.__send__(setter, decode(bytes)) unless repeated? | |||
return message_instance.__send__(getter) << decode(bytes) unless packed? | |||
return message_instance[name] = decode(bytes) unless repeated? |
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 this still flow through the setter? I'm exactly sure why we needed to be calling the setter here, but I want to make sure this isn't unintentionally altering behavior.
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.
Though perhaps that is the point here?
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.
The []=
method now is the setter and []
is now the getter, so it should be the same. The old setter and getter still exist for runtime access of the proto, but they alias to the former two methods now.
For just a little more background, []
and []=
used to alias to the setter and getter instead, but we switched that around so that we didn't have this weird dynamic usage of the setters and getters.
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.
Got it. No more __send__(xxx)
.
@embark I don't have write access, but for any reviewers that do, I reviewed this and 👍. Flipping around the |
Just remove the |
1ceee2f
to
ad05d79
Compare
ad05d79
to
1ceee2f
Compare
1ceee2f
to
154fbad
Compare
Many thanks to all the reviews and responses! -- Removed |
CC @film42 all green! |
Clean up dynamic code generation in prep for extension namespacing
Hmm. I used to have push access to rubygems.. looks like someone is going to need to add me again. Tomorrow I'll cut this as |
@film42 Thanks! There will be a few PRs to come to get support for custom options if you want to wait for that before cutting a new release, though it's up to you. |
FYI @film42 @liveh2o @zachmargolis @nerdrew I just discovered that this PR changed the behavior of the Old behavior for repeated fields:
note that nothing happens when New behavior for repeated fields:
Old behavior for optional fields:
again, nothing happens to the field, it isn't even cleared. New behavior for optional fields:
now the optional field has been cleared. NOTE: the new |
…ters Clean up dynamic code generation in prep for extension namespacing
CC @nerdrew