@@ -353,9 +353,18 @@ def __init__(self, name, full_name, filename, containing_type, fields,
353
353
self .oneofs_by_name = dict ((o .name , o ) for o in self .oneofs )
354
354
for oneof in self .oneofs :
355
355
oneof .containing_type = self
356
- self .syntax = syntax or "proto2"
356
+ self ._deprecated_syntax = syntax or "proto2"
357
357
self ._is_map_entry = is_map_entry
358
358
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
+
359
368
@property
360
369
def fields_by_camelcase_name (self ):
361
370
"""Same FieldDescriptor objects as in :attr:`fields`, but indexed by
@@ -621,7 +630,7 @@ def has_presence(self):
621
630
# compatibility. FieldDescriptor.file was added in cl/153110619
622
631
# Some old/generated code didn't link file to FieldDescriptor.
623
632
# TODO: remove syntax usage b/240619313
624
- return self .containing_type .syntax == 'proto2'
633
+ return self .containing_type ._deprecated_syntax == 'proto2'
625
634
626
635
@property
627
636
def is_packed (self ):
@@ -634,7 +643,7 @@ def is_packed(self):
634
643
field_type == FieldDescriptor .TYPE_MESSAGE or
635
644
field_type == FieldDescriptor .TYPE_BYTES ):
636
645
return False
637
- if self .containing_type .syntax == 'proto2' :
646
+ if self .containing_type ._deprecated_syntax == 'proto2' :
638
647
return self .has_options and self .GetOptions ().packed
639
648
else :
640
649
return (not self .has_options or
@@ -743,7 +752,7 @@ def is_closed(self):
743
752
Care should be taken when using this function to respect the target
744
753
runtime's enum handling quirks.
745
754
"""
746
- return self .file .syntax == 'proto2'
755
+ return self .file ._deprecated_syntax == 'proto2'
747
756
748
757
def CopyToProto (self , proto ):
749
758
"""Copies this to a descriptor_pb2.EnumDescriptorProto.
@@ -1083,7 +1092,7 @@ def __init__(self, name, package, options=None,
1083
1092
self .message_types_by_name = {}
1084
1093
self .name = name
1085
1094
self .package = package
1086
- self .syntax = syntax or "proto2"
1095
+ self ._deprecated_syntax = syntax or "proto2"
1087
1096
self .serialized_pb = serialized_pb
1088
1097
1089
1098
self .enum_types_by_name = {}
@@ -1092,6 +1101,15 @@ def __init__(self, name, package, options=None,
1092
1101
self .dependencies = (dependencies or [])
1093
1102
self .public_dependencies = (public_dependencies or [])
1094
1103
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
+
1095
1113
def CopyToProto (self , proto ):
1096
1114
"""Copies this to a descriptor_pb2.FileDescriptorProto.
1097
1115
0 commit comments