protocolbuffers / protobuf

Protocol Buffers - Google's data interchange format
http://protobuf.dev
Other
65.64k stars 15.49k forks source link

[Python] Generate trailing underscore for fields that shadow reserved keywords #17332

Open noahseger opened 4 months ago

noahseger commented 4 months ago

What language does this apply to? Python

Describe the problem you are trying to solve.

Fields named, for example from, are inaccessible because they shadow the Python keyword.

https://stackoverflow.com/a/30145419

Describe the solution you'd like Additionally (backwards compatible) generate a field named like from_ in the Python protoc and PYI protoc.

This convention is documented in PEP8:

single_trailingunderscore: used by convention to avoid conflicts with Python keyword, e.g.

https://peps.python.org/pep-0008/#descriptive-naming-styles

Describe alternatives you've considered getattr/setattr hacks.

Additional context N/A

honglooker commented 2 months ago

FYI @anandolee