protocolbuffers / protocolbuffers/protobuf
[Python] Generate trailing underscore for fields that shadow reserved keywords
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 72k
- Forks
- 16.3k
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 140
Description
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_trailing_underscore_: 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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the Python protoc and PYI protoc generation paths and inspect how fields named with Python keywords are currently emitted. Done means keyword-shadowing fields also expose the documented trailing-underscore form while preserving existing generated APIs; check the relevant generator behavior and its existing validation coverage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100