Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional not oneof #49

Merged
merged 3 commits into from
May 1, 2023
Merged

Optional not oneof #49

merged 3 commits into from
May 1, 2023

Conversation

gabe-l-hart
Copy link
Collaborator

Description

This PR fixes support for Optional[X] fields:

@dataclass
class Foo:
    foo: Optional[int]

dataclass_to_proto("foo.bar", Foo)

The fix is robust to various combinations of wrapping between Annotated, Optional, and Union.

There's no valid case for a oneof where one of the elements is NoneType, so
this must be an `Optional` type and should should be unwrapped

Signed-off-by: Gabe Goodhart <ghart@us.ibm.com>
This makes Optional[X] not be a oneof, but Optional[Union[X, Y]] be a oneof

Signed-off-by: Gabe Goodhart <ghart@us.ibm.com>
…vors

Signed-off-by: Gabe Goodhart <ghart@us.ibm.com>
@gabe-l-hart gabe-l-hart merged commit d0b57a6 into main May 1, 2023
@gabe-l-hart gabe-l-hart deleted the OptionalNotOneof branch May 1, 2023 23:13
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.

1 participant