You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
tl;dr: The result of proto.encode_text(struct(foo="hello", bar=None)) should be "{foo: "hello"} rather than an error. Otherwise I need to use hasattr a whole lot, which seems bad.
I'm ducktyping a proto in Starlark as part of a conversion to ITS that will likely be mandated all over the googlesphere, and I've hit this annoyance. My top-level message has an optional embedded message field, which has a required field. I need the values accessible in both Starlark and in C++, and wish to use proto.encode_text to avoid needing to maintain separate Starlark and textproto versions of each config file.
The only way to represent the absence of the legacy field now is to omit it from my starlark struct, as in my_duck_proto = struct(other_data="blah"). The proto.encode_text of this looks like '{other_data: "blah"}' which is legal textproto. My annoyance with this is I have to check if hasattr(my_duck_proto, "legacy") instead of if my_duck_proto.legacy == None. Which goes against the python style guide, which we're supposed to be mostly using for Starlark.
Why other representations don't work: If I do proto.encode_text(struct(other_data="blah", legacy=struct())) then I get '{other_data: "blah" legacy {}} which can't be parsed because the required field is missing. Similarly proto.encode_text(struct(other_data="blah", legacy=struct(token=""))), I get {other_data: "blah" legacy {token: ""}} which is also an error.
Would this be okay?
The text was updated successfully, but these errors were encountered:
tl;dr: The result of
proto.encode_text(struct(foo="hello", bar=None))
should be"{foo: "hello"}
rather than an error. Otherwise I need to usehasattr
a whole lot, which seems bad.I'm ducktyping a proto in Starlark as part of a conversion to ITS that will likely be mandated all over the googlesphere, and I've hit this annoyance. My top-level message has an optional embedded message field, which has a required field. I need the values accessible in both Starlark and in C++, and wish to use
proto.encode_text
to avoid needing to maintain separate Starlark and textproto versions of each config file.The only way to represent the absence of the
legacy
field now is to omit it from my starlark struct, as inmy_duck_proto = struct(other_data="blah")
. Theproto.encode_text
of this looks like'{other_data: "blah"}'
which is legal textproto. My annoyance with this is I have to checkif hasattr(my_duck_proto, "legacy")
instead ofif my_duck_proto.legacy == None
. Which goes against the python style guide, which we're supposed to be mostly using for Starlark.Why other representations don't work: If I do
proto.encode_text(struct(other_data="blah", legacy=struct()))
then I get'{other_data: "blah" legacy {}}
which can't be parsed because the required field is missing. Similarlyproto.encode_text(struct(other_data="blah", legacy=struct(token="")))
, I get{other_data: "blah" legacy {token: ""}}
which is also an error.Would this be okay?
The text was updated successfully, but these errors were encountered: