@@ -153,6 +153,7 @@ class ProtoContentBase:
153
153
154
154
path : List [int ]
155
155
comment_indent : int = 4
156
+ parent : Union ["Messsage" , "OutputTemplate" ]
156
157
157
158
def __post_init__ (self ):
158
159
"""Checks that no fake default fields were left as placeholders."""
@@ -355,18 +356,21 @@ def get_field_string(self, indent: int = 4) -> str:
355
356
"""Construct string representation of this field as a field."""
356
357
name = f"{ self .py_name } "
357
358
annotations = f": { self .annotation } "
359
+ field_args = ", " .join (
360
+ (["" ] + self .betterproto_field_args ) if self .betterproto_field_args else []
361
+ )
358
362
betterproto_field_type = (
359
363
f"betterproto.{ self .field_type } _field({ self .proto_obj .number } "
360
- + f" { self . betterproto_field_args } "
364
+ + field_args
361
365
+ ")"
362
366
)
363
367
return name + annotations + " = " + betterproto_field_type
364
368
365
369
@property
366
- def betterproto_field_args (self ):
367
- args = ""
370
+ def betterproto_field_args (self ) -> List [ str ] :
371
+ args = []
368
372
if self .field_wraps :
369
- args = args + f", wraps={ self .field_wraps } "
373
+ args . append ( f" wraps={ self .field_wraps } ")
370
374
return args
371
375
372
376
@property
@@ -473,10 +477,10 @@ def annotation(self) -> str:
473
477
@dataclass
474
478
class OneOfFieldCompiler (FieldCompiler ):
475
479
@property
476
- def betterproto_field_args (self ) -> " str" :
480
+ def betterproto_field_args (self ) -> List [ str ] :
477
481
args = super ().betterproto_field_args
478
482
group = self .parent .proto_obj .oneof_decl [self .proto_obj .oneof_index ].name
479
- args = args + f', group="{ group } "'
483
+ args . append ( f' group="{ group } "')
480
484
return args
481
485
482
486
@@ -505,16 +509,13 @@ def __post_init__(self):
505
509
self .proto_v_type = self .proto_obj .Type .Name (nested .field [1 ].type )
506
510
super ().__post_init__ () # call FieldCompiler-> MessageCompiler __post_init__
507
511
508
- def get_field_string (self , indent : int = 4 ) -> str :
509
- """Construct string representation of this field."""
510
- name = f"{ self .py_name } "
511
- annotations = f": { self .annotation } "
512
- betterproto_field_type = (
513
- f"betterproto.map_field("
514
- f"{ self .proto_obj .number } , betterproto.{ self .proto_k_type } , "
515
- f"betterproto.{ self .proto_v_type } )"
516
- )
517
- return name + annotations + " = " + betterproto_field_type
512
+ @property
513
+ def betterproto_field_args (self ) -> List [str ]:
514
+ return [f"betterproto.{ self .proto_k_type } " , f"betterproto.{ self .proto_v_type } " ]
515
+
516
+ @property
517
+ def field_type (self ) -> str :
518
+ return "map"
518
519
519
520
@property
520
521
def annotation (self ):
0 commit comments