Skip to content

Type Python WhichOneof in generated stubs#28622

Open
tamird wants to merge 2 commits into
protocolbuffers:mainfrom
tamird:tamird/type-python-which-oneof
Open

Type Python WhichOneof in generated stubs#28622
tamird wants to merge 2 commits into
protocolbuffers:mainfrom
tamird:tamird/type-python-which-oneof

Conversation

@tamird

@tamird tamird commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Depends on #28621.

WhichOneof currently loses the relationship between a oneof group and
its possible members in generated Python stubs. Emit literal-aware,
positional-only signatures so callers can reject invalid group names and
exhaustively handle the selected member. Preserve byte-string group names
supported by the default runtimes, cover synthetic proto3-optional groups,
reject calls on messages without oneofs, and avoid a duplicate declaration
when a field shadows the method.

Extend the generated-stub tests with single, multiple, nested, synthetic,
keyword, and shadowed oneofs plus messages without oneofs. All four type
checkers snapshot inferred return types, invalid groups, invalid keyword
calls, and non-exhaustive handling.

@tamird
tamird requested a review from a team as a code owner July 16, 2026 20:21
@tamird
tamird requested review from zhangskz and removed request for a team July 16, 2026 20:21
tamird added 2 commits July 16, 2026 14:01
Add generated-stub golden and syntax coverage together with a hermetic
mypy, ty, Pyright, and Pyrefly consumer test. Exercise imports, maps,
well-known types, proto2 self-field collisions, and realistic
construction. Snapshot each checker's inferred types and diagnostics
from one expression fixture, including invalid field values and unknown
constructor arguments.

Run the checker test once in the Linux and macOS Bazel lanes instead of
every Python and UPB matrix lane. Keep its dependencies
development-only. Integrate generated-stub goldens with stale-file
regeneration and provide an explicit fixer for the semantic checker
snapshots.
Emit literal-aware, positional-only WhichOneof signatures in generated
Python stubs so callers can reject invalid group names and exhaustively
handle members. Accept byte-string group names supported by the default
runtimes, reject calls on messages without oneofs, and avoid a duplicate
declaration when a field shadows the method. Include synthetic
proto3-optional groups because runtime reflection exposes them.

Extend the generated-stub harness with single, multiple, nested,
synthetic, keyword, and shadowed oneofs plus messages without oneofs.
Snapshot inferred return types, invalid groups, keyword calls, and
missing-branch diagnostics with every type checker.
@tamird
tamird force-pushed the tamird/type-python-which-oneof branch from a22e561 to 1480b55 Compare July 16, 2026 21:07
@zhangskz
zhangskz requested a review from anandolee July 17, 2026 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants