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

Commit 95a873a

Browse files
committed
Fix typin gerrors with unwrap
1 parent 698ede5 commit 95a873a

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

poetry.lock

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ packages = [
1313

1414
[tool.poetry.dependencies]
1515
python = "^3.10"
16-
betterproto2 = "^0.1.1"
16+
betterproto2 = "^0.1.3"
1717
# The Ruff version is pinned. To update it, also update it in .pre-commit-config.yaml
1818
ruff = "~0.7.4"
1919
grpclib = "^0.4.1"

src/betterproto2_compiler/plugin/models.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
)
3434

3535
import betterproto2
36+
from betterproto2 import unwrap
3637
from betterproto2.lib.google.protobuf import (
3738
DescriptorProto,
3839
EnumDescriptorProto,
@@ -111,7 +112,7 @@ def get_comment(
111112
proto_file: "FileDescriptorProto",
112113
path: list[int],
113114
) -> str:
114-
for sci_loc in proto_file.source_code_info.location:
115+
for sci_loc in unwrap(proto_file.source_code_info).location:
115116
if list(sci_loc.path) == path:
116117
all_comments = list(sci_loc.leading_detached_comments)
117118
if sci_loc.leading_comments:
@@ -429,23 +430,23 @@ def optional(self) -> bool:
429430
@property
430431
def betterproto_field_args(self) -> list[str]:
431432
args = super().betterproto_field_args
432-
group = self.message.proto_obj.oneof_decl[self.proto_obj.oneof_index].name
433+
group = self.message.proto_obj.oneof_decl[unwrap(self.proto_obj.oneof_index)].name
433434
args.append(f'group="{group}"')
434435
return args
435436

436437

437438
@dataclass(kw_only=True)
438439
class MapEntryCompiler(FieldCompiler):
439-
py_k_type: str | None = None
440-
py_v_type: str | None = None
440+
py_k_type: str = ""
441+
py_v_type: str = ""
441442
proto_k_type: str = ""
442443
proto_v_type: str = ""
443444

444445
def ready(self) -> None:
445446
"""Explore nested types and set k_type and v_type if unset."""
446447
map_entry = f"{self.proto_obj.name.replace('_', '').lower()}entry"
447448
for nested in self.message.proto_obj.nested_type:
448-
if nested.name.replace("_", "").lower() == map_entry and nested.options.map_entry:
449+
if nested.name.replace("_", "").lower() == map_entry and unwrap(nested.options).map_entry:
449450
# Get Python types
450451
self.py_k_type = FieldCompiler(
451452
source_file=self.source_file,
@@ -463,8 +464,8 @@ def ready(self) -> None:
463464
).py_type
464465

465466
# Get proto types
466-
self.proto_k_type = FieldDescriptorProtoType(nested.field[0].type).name
467-
self.proto_v_type = FieldDescriptorProtoType(nested.field[1].type).name
467+
self.proto_k_type = unwrap(FieldDescriptorProtoType(nested.field[0].type).name)
468+
self.proto_v_type = unwrap(FieldDescriptorProtoType(nested.field[1].type).name)
468469
return
469470

470471
raise ValueError("can't find enum")

0 commit comments

Comments
 (0)