@@ -353,9 +353,18 @@ def __init__(self, name, full_name, filename, containing_type, fields,
353353 self .oneofs_by_name = dict ((o .name , o ) for o in self .oneofs )
354354 for oneof in self .oneofs :
355355 oneof .containing_type = self
356- self .syntax = syntax or "proto2"
356+ self ._deprecated_syntax = syntax or "proto2"
357357 self ._is_map_entry = is_map_entry
358358
359+ @property
360+ def syntax (self ):
361+ warnings .warn (
362+ 'descriptor.syntax is deprecated. It will be removed'
363+ ' soon. Most usages are checking field descriptors. Consider to use'
364+ ' has_presence, is_packed on field descriptors.'
365+ )
366+ return self ._deprecated_syntax
367+
359368 @property
360369 def fields_by_camelcase_name (self ):
361370 """Same FieldDescriptor objects as in :attr:`fields`, but indexed by
@@ -621,7 +630,7 @@ def has_presence(self):
621630 # compatibility. FieldDescriptor.file was added in cl/153110619
622631 # Some old/generated code didn't link file to FieldDescriptor.
623632 # TODO: remove syntax usage b/240619313
624- return self .containing_type .syntax == 'proto2'
633+ return self .containing_type ._deprecated_syntax == 'proto2'
625634
626635 @property
627636 def is_packed (self ):
@@ -634,7 +643,7 @@ def is_packed(self):
634643 field_type == FieldDescriptor .TYPE_MESSAGE or
635644 field_type == FieldDescriptor .TYPE_BYTES ):
636645 return False
637- if self .containing_type .syntax == 'proto2' :
646+ if self .containing_type ._deprecated_syntax == 'proto2' :
638647 return self .has_options and self .GetOptions ().packed
639648 else :
640649 return (not self .has_options or
@@ -743,7 +752,7 @@ def is_closed(self):
743752 Care should be taken when using this function to respect the target
744753 runtime's enum handling quirks.
745754 """
746- return self .file .syntax == 'proto2'
755+ return self .file ._deprecated_syntax == 'proto2'
747756
748757 def CopyToProto (self , proto ):
749758 """Copies this to a descriptor_pb2.EnumDescriptorProto.
@@ -1083,7 +1092,7 @@ def __init__(self, name, package, options=None,
10831092 self .message_types_by_name = {}
10841093 self .name = name
10851094 self .package = package
1086- self .syntax = syntax or "proto2"
1095+ self ._deprecated_syntax = syntax or "proto2"
10871096 self .serialized_pb = serialized_pb
10881097
10891098 self .enum_types_by_name = {}
@@ -1092,6 +1101,15 @@ def __init__(self, name, package, options=None,
10921101 self .dependencies = (dependencies or [])
10931102 self .public_dependencies = (public_dependencies or [])
10941103
1104+ @property
1105+ def syntax (self ):
1106+ warnings .warn (
1107+ 'descriptor.syntax is deprecated. It will be removed'
1108+ ' soon. Most usages are checking field descriptors. Consider to use'
1109+ ' has_presence, is_packed on field descriptors.'
1110+ )
1111+ return self ._deprecated_syntax
1112+
10951113 def CopyToProto (self , proto ):
10961114 """Copies this to a descriptor_pb2.FileDescriptorProto.
10971115
0 commit comments