aboutsummaryrefslogtreecommitdiffhomepage
path: root/python
diff options
context:
space:
mode:
authorGravatar Jie Luo <anandolee@gmail.com>2017-11-22 13:59:11 -0800
committerGravatar GitHub <noreply@github.com>2017-11-22 13:59:11 -0800
commit45d99a15f369a698a7f5be790ced1fe7029e6139 (patch)
tree8ee8dcbd793f22e74a9d88e517b873c141f0b44d /python
parent98836a56e616f3bc387e3c66133b1ad320f36d80 (diff)
Add _file_desc_by_toplevel_extension back
Add _file_desc_by_toplevel_extension back for compatibility issue with 3.4.1. _file_desc_by_toplevel_extension is a temporary solution for FieldDescriptor.file. FieldDescriptor.file was added in code gen. However, we need to keep it for some time for compatibility reason (with 3.4.1 only). May try to remove it after 2 years.
Diffstat (limited to 'python')
-rw-r--r--python/google/protobuf/descriptor_pool.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/python/google/protobuf/descriptor_pool.py b/python/google/protobuf/descriptor_pool.py
index cb7146b6..f4c533a4 100644
--- a/python/google/protobuf/descriptor_pool.py
+++ b/python/google/protobuf/descriptor_pool.py
@@ -127,6 +127,9 @@ class DescriptorPool(object):
self._service_descriptors = {}
self._file_descriptors = {}
self._toplevel_extensions = {}
+ # TODO(jieluo): Remove _file_desc_by_toplevel_extension after
+ # maybe year 2020 for compatibility issue (with 3.4.1 only).
+ self._file_desc_by_toplevel_extension = {}
# We store extensions in two two-level mappings: The first key is the
# descriptor of the message being extended, the second key is the extension
# full name or its tag number.
@@ -252,6 +255,12 @@ class DescriptorPool(object):
"""
self._AddFileDescriptor(file_desc)
+ # TODO(jieluo): This is a temporary solution for FieldDescriptor.file.
+ # FieldDescriptor.file is added in code gen. Remove this solution after
+ # maybe 2020 for compatibility reason (with 3.4.1 only).
+ for extension in file_desc.extensions_by_name.values():
+ self._file_desc_by_toplevel_extension[
+ extension.full_name] = file_desc
def _AddFileDescriptor(self, file_desc):
"""Adds a FileDescriptor to the pool, non-recursively.
@@ -331,7 +340,7 @@ class DescriptorPool(object):
pass
try:
- return self._toplevel_extensions[symbol].file
+ return self._file_desc_by_toplevel_extension[symbol]
except KeyError:
pass