Type Python WhichOneof in generated stubs#28622
Open
tamird wants to merge 2 commits into
Open
Conversation
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
force-pushed
the
tamird/type-python-which-oneof
branch
from
July 16, 2026 21:07
a22e561 to
1480b55
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Depends on #28621.
WhichOneofcurrently loses the relationship between a oneof group andits 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.