@@ -83,6 +83,9 @@ for member in message.structure.members:
8383 if member .name != EMPTY_STRUCTURE_REQUIRED_MEMBER_NAME :
8484 imports .setdefault (
8585 ' import builtins' , []) # used for @builtins.property
86+ if member .has_annotation (' deprecated' ):
87+ imports .setdefault (
88+ ' from typing_extensions import deprecated as _deprecated' , [])
8689 if isinstance (type_, BasicType) and type_ .typename in FLOATING_POINT_TYPES :
8790 imports .setdefault (
8891 ' import math' , []) # used for math.isinf
@@ -417,7 +420,7 @@ if isinstance(type_, AbstractNestedType):
417420 typename .append (self .__class__ .__name__ )
418421 args : list[str] = []
419422 for s, t in zip (self .get_fields_and_field_types ().keys (), self .SLOT_TYPES ):
420- field = getattr (self, s)
423+ field = getattr (self, ' _ ' + s)
421424 fieldstr = repr (field)
422425 # We use Python array type for fields that can be directly stored
423426 # in them, and "normal" sequences for everything else. If it is
@@ -446,9 +449,9 @@ if isinstance(type_, AbstractNestedType):
446449@ [ continue ]@
447450@ [ end if ]@
448451@ [ if isinstance (member .type , Array ) and isinstance (member .type .value_type , BasicType) and member .type .value_type .typename in SPECIAL_NESTED_BASIC_TYPES]@
449- if any (self.@ (member .name ) != other.@ (member .name )):
452+ if any (self ._ @ (member .name ) != other ._ @ (member .name )):
450453@ [ else ]@
451- if self.@ (member .name ) != other.@ (member .name ):
454+ if self ._ @ (member .name ) != other ._ @ (member .name ):
452455@ [ end if ]@
453456 return False
454457@ [end for ]@
@@ -476,12 +479,24 @@ array_type_commment = ''
476479if isinstance (member .type , (Array , AbstractSequence)):
477480 array_type_commment = ' # typing.Annotated can be remove after mypy 1.16+ see mypy#3004'
478481}@
482+ @ [ if member .has_annotation (' deprecated' )]@
483+ @ {
484+ deprecation_annotation = member .get_annotation_value (' deprecated' )
485+ deprecation_text = deprecation_annotation .get (' text' , ' ' ) if isinstance (deprecation_annotation, dict) else ' '
486+ }@
487+ @ [ end if ]@
479488 @@builtins .property @ (noqa_string)
489+ @ [ if member .has_annotation (' deprecated' )]@
490+ @ @ _deprecated (' @(deprecation_text)' )@ (noqa_string)
491+ @ [ end if ]@
480492 def @ (member .name )(self ) -> @ (type_annotations_getter[member .name ]): @ (noqa_string)@ (array_type_commment)
481493 """ Message field '@(member.name)'."""
482494 return self ._ @ (member .name )
483495
484496 @@@ (member .name ).setter @ (noqa_string)
497+ @ [ if member .has_annotation (' deprecated' )]@
498+ @ @ _deprecated (' @(deprecation_text)' )@ (noqa_string)
499+ @ [ end if ]@
485500 def @ (member .name )(self, value : @ (type_annotations_setter[member .name ])) -> None : @ (noqa_string)
486501@ [ if isinstance (member .type , AbstractNestedType)]@
487502 if isinstance (value, collections .abc .Set ):
0 commit comments