Skip to content
This repository was archived by the owner on Jun 9, 2025. It is now read-only.

Commit 435e0f2

Browse files
Remove synthetic oneofs (#38)
* Fix synthetic oneofs * Bump to 0.2.1
1 parent dc25c97 commit 435e0f2

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "betterproto2_compiler"
3-
version = "0.2.0"
3+
version = "0.2.1"
44
description = "Compiler for betterproto2"
55
authors = ["Adrien Vannson <[email protected]>", "Daniel G. Taylor <[email protected]>"]
66
readme = "README.md"

src/betterproto2_compiler/plugin/parser.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -227,14 +227,21 @@ def read_protobuf_type(
227227
)
228228
)
229229

230-
for index, oneof in enumerate(item.oneof_decl):
231-
message_data.oneofs.append(
232-
OneofCompiler(
233-
source_file=source_file,
234-
path=path + [8, index],
235-
proto_obj=oneof,
230+
# Synthetic oneofs are generated for optional fields. We should not generate code or documentation for them.
231+
is_synthetic_oneof = [True for _ in item.oneof_decl]
232+
for field in item.field:
233+
if field.oneof_index is not None and not field.proto3_optional:
234+
is_synthetic_oneof[field.oneof_index] = False
235+
236+
for index, (oneof, is_synthetic) in enumerate(zip(item.oneof_decl, is_synthetic_oneof)):
237+
if not is_synthetic:
238+
message_data.oneofs.append(
239+
OneofCompiler(
240+
source_file=source_file,
241+
path=path + [8, index],
242+
proto_obj=oneof,
243+
)
236244
)
237-
)
238245

239246
elif isinstance(item, EnumDescriptorProto):
240247
# Enum

0 commit comments

Comments
 (0)