Skip to content
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

Support for struct.proto well-known-type #513

Open
negz opened this issue Oct 2, 2023 · 1 comment
Open

Support for struct.proto well-known-type #513

negz opened this issue Oct 2, 2023 · 1 comment

Comments

@negz
Copy link

negz commented Oct 2, 2023

It's possible to use google/protobuf.struct.proto today, but pretty awkward. For example:

struct = proto.file("google/protobuf/struct.proto")

msg.struct_field = struct.Struct{
  fields={
    "widgets": struct.Value(number_value=42)
  }
}

I'd prefer to be able to treat a Struct as if it were a Python dictionary. More like this:

msg.struct_field = {"widgets": 42}
msg.struct_field["watchers"] = 8

That said, I'm not sure whether it makes sense for the proto Starlark module to have native awareness of the Struct type, or whether a new protostruct module should be introduced? Perhaps something like this:

msg.struct_field = protostruct.from_dict({"widgets": 42})
@negz
Copy link
Author

negz commented Oct 2, 2023

It seems like perhaps Python generated code just supports it "natively", per https://protobuf.dev/reference/python/python-generated/#struct. Perhaps Starlark should do the same?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant