Open negz opened 9 months ago
I think part of what I'm looking for, especially for maps (in the context of https://github.com/google/starlark-go/pull/511), is an API like this:
if msg.map_field == None:
msg.map_field = {}
msg.map_field["key"] = "value"
This is similar to what was mentioned in https://github.com/stripe/skycfg/issues/23#issuecomment-444221347. I can use not proto.has
instead of == None
easily enough, but I'll still end up with a frozen field because the msg.map_field = {}
doesn't effectively replace the default value with a usable dict/MapField.
I'm new to Starlark[^1]. I'm attempting to write a little Go function that essentially defers answering a gRPC request to a Starlark script. Like this:
My first intuition was to try doing something like this[^2]:
However, I was surprised to be told that
rsp.results
was a frozen repeated field. Looking atproto.go
I realized this was the default value, so I tried this:Unfortunately the field is still frozen. I'm guessing because the
Has()
method ofprotoreflect.Message
only considers a message to have a repeated field (and thus I guess by extension map field) if it's non-empty.With all that said, I'm curious:
I'm not sure it's possible to make them writable/unfrozen by default but I wanted to ask before I dug in too deeply.
[^1]: I guess technically I used it in a bunch of
BUILD
files a decade ago, but I've forgotten all about that. 🙂 [^2]: I added theappend
method in https://github.com/google/starlark-go/pull/511.