protobuf icon indicating copy to clipboard operation
protobuf copied to clipboard

Formally document and support python-protobuf-attribute-setting-by-keyword-argument-to-constructor

Open nathanielmanistaatgoogle opened this issue 7 years ago • 2 comments

For years I've favored writing code shaped like

my_message = my_module_pb2.MyMessage(my_first_attribute=3, my_second_attribute=4)

rather than

my_message = my_module_pb2.MyMessage()
my_message.my_first_attribute = 3
my_message.my_second_attribute = 4

. Are these construction semantics documented anywhere? Could they be, along with the similar semantics of

my_message.repeated_sub_message.add(up='↑', down='↓')

rather than

my_sub_message = my_message.repeated_sub_message.add()
my_sub_message.up = '↑'
my_sub_message.down = '↓'

?

Would this page be the right place for such documentation?

I also find it confusing that the doc indicate this is wrong:

foo = Foo()
foo.bar = Bar()  # WRONG!

But this seem to be ok:

Foo(bar=Bar())

xiaochuanyu avatar Apr 17 '20 22:04 xiaochuanyu

I think this is a better place:

https://developers.google.com/protocol-buffers/docs/pythontutorial#the-protocol-buffer-api

anandolee avatar Sep 01 '22 21:09 anandolee

We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please add a comment.

This issue is labeled inactive because the last activity was over 90 days ago.

github-actions[bot] avatar Jun 17 '24 10:06 github-actions[bot]

Still a problem. *pokes bot in the eyes*

cvrebert avatar Jun 17 '24 15:06 cvrebert