From 3db9d1f58d6f39a5fe9e2116d49ad767fe43f1d2 Mon Sep 17 00:00:00 2001 From: Adrien Vannson Date: Sun, 11 May 2025 23:42:48 +0200 Subject: [PATCH 1/2] Fix builtin with annotations --- src/betterproto2_compiler/plugin/models.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/betterproto2_compiler/plugin/models.py b/src/betterproto2_compiler/plugin/models.py index 66a47d41..52b69d54 100644 --- a/src/betterproto2_compiler/plugin/models.py +++ b/src/betterproto2_compiler/plugin/models.py @@ -441,14 +441,15 @@ def annotations(self) -> list[str]: def annotation(self) -> str: py_type = self.py_type + if self.use_builtins: + py_type = f"builtins.{py_type}" + # Add the pydantic annotation if needed if self.output_file.settings.pydantic_dataclasses: annotations = self.annotations if annotations: py_type = f"typing.Annotated[{py_type}, {', '.join(annotations)}]" - if self.use_builtins: - py_type = f"builtins.{py_type}" if self.repeated: return f"list[{py_type}]" if self.optional: From b6b11945aa8353d8ed854e53f9c713414ac32b43 Mon Sep 17 00:00:00 2001 From: Adrien Vannson Date: Sun, 11 May 2025 23:43:22 +0200 Subject: [PATCH 2/2] Add new tests --- .../encoding_decoding/encoding_decoding.proto | 15 +++++++++++++++ .../manual_validation/manual_validation.proto | 7 +++++++ 2 files changed, 22 insertions(+) create mode 100644 tests/inputs/encoding_decoding/encoding_decoding.proto create mode 100644 tests/inputs/manual_validation/manual_validation.proto diff --git a/tests/inputs/encoding_decoding/encoding_decoding.proto b/tests/inputs/encoding_decoding/encoding_decoding.proto new file mode 100644 index 00000000..2cf8e391 --- /dev/null +++ b/tests/inputs/encoding_decoding/encoding_decoding.proto @@ -0,0 +1,15 @@ +syntax = "proto3"; + +package encoding_decoding; + +message Overflow32 { + uint32 uint = 1; + int32 int = 2; + sint32 sint = 3; +} + +message Overflow64 { + uint64 uint = 1; + int64 int = 2; + sint64 sint = 3; +} diff --git a/tests/inputs/manual_validation/manual_validation.proto b/tests/inputs/manual_validation/manual_validation.proto new file mode 100644 index 00000000..88603113 --- /dev/null +++ b/tests/inputs/manual_validation/manual_validation.proto @@ -0,0 +1,7 @@ +syntax = "proto3"; + +package manual_validation; + +message Msg { + uint32 x = 1; +}