Skip to content

Conversation

@aidandj
Copy link
Collaborator

@aidandj aidandj commented Nov 28, 2025

I've occasionally found myself wanting type aliases for these literals so you can properly type fields that call Clear or HasFields.

I'd like to do Oneof as well, because then you can separate out Oneof pattern match chains into separate functions.

Oneof has the type overloads though, and the aliases are slightly more complicated. That will be another PR.

…for typing field manipulation functions

Signed-off-by: Aidan Jensen <aidandj.github@gmail.com>
Signed-off-by: Aidan Jensen <aidandj.github@gmail.com>
@aidandj aidandj requested a review from nipunn1313 November 28, 2025 06:57
@aidandj aidandj force-pushed the aidan/clear-has-field-type-aliases branch from 1ebaa01 to 411eb53 Compare November 28, 2025 22:54
Add WhichOneofArgType and WhichOneofReturnType aliases

Signed-off-by: Aidan Jensen <aidandj.github@gmail.com>
@aidandj aidandj force-pushed the aidan/clear-has-field-type-aliases branch from 411eb53 to b5dcfc2 Compare November 28, 2025 22:55
@aidandj
Copy link
Collaborator Author

aidandj commented Nov 28, 2025

WhichOneof type aliases ended up being simple.

At first I was just going to number them, but then I realized that may not be static if new oneofs were added, unless i ordered them by field number. So I just appended the oneof name to the end of the field. All proto message names are valid python identifiers, so this was the safer, and more descriptive way. The name isn't always the prettiest, but its unique and descriptive.

Copy link
Owner

@nipunn1313 nipunn1313 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oof complex impl, but seems good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants