protocolbuffers / protocolbuffers/protobuf

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

Open
#17,332 11 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

editions keep open python
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.