33
33
)
34
34
35
35
import betterproto2
36
+ from betterproto2 import unwrap
36
37
from betterproto2 .lib .google .protobuf import (
37
38
DescriptorProto ,
38
39
EnumDescriptorProto ,
@@ -111,7 +112,7 @@ def get_comment(
111
112
proto_file : "FileDescriptorProto" ,
112
113
path : list [int ],
113
114
) -> str :
114
- for sci_loc in proto_file .source_code_info .location :
115
+ for sci_loc in unwrap ( proto_file .source_code_info ) .location :
115
116
if list (sci_loc .path ) == path :
116
117
all_comments = list (sci_loc .leading_detached_comments )
117
118
if sci_loc .leading_comments :
@@ -429,23 +430,23 @@ def optional(self) -> bool:
429
430
@property
430
431
def betterproto_field_args (self ) -> list [str ]:
431
432
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
433
434
args .append (f'group="{ group } "' )
434
435
return args
435
436
436
437
437
438
@dataclass (kw_only = True )
438
439
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 = ""
441
442
proto_k_type : str = ""
442
443
proto_v_type : str = ""
443
444
444
445
def ready (self ) -> None :
445
446
"""Explore nested types and set k_type and v_type if unset."""
446
447
map_entry = f"{ self .proto_obj .name .replace ('_' , '' ).lower ()} entry"
447
448
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 :
449
450
# Get Python types
450
451
self .py_k_type = FieldCompiler (
451
452
source_file = self .source_file ,
@@ -463,8 +464,8 @@ def ready(self) -> None:
463
464
).py_type
464
465
465
466
# 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 )
468
469
return
469
470
470
471
raise ValueError ("can't find enum" )
0 commit comments