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

Fix builtins with annotations #81

Merged
merged 2 commits into from
May 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/betterproto2_compiler/plugin/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
15 changes: 15 additions & 0 deletions tests/inputs/encoding_decoding/encoding_decoding.proto
Original file line number Diff line number Diff line change
@@ -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;
}
7 changes: 7 additions & 0 deletions tests/inputs/manual_validation/manual_validation.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
syntax = "proto3";

package manual_validation;

message Msg {
uint32 x = 1;
}
Loading