diff --git a/python/google/protobuf/descriptor_pool.py b/python/google/protobuf/descriptor_pool.py index dccac5e714..1ebf11834a 100644 --- a/python/google/protobuf/descriptor_pool.py +++ b/python/google/protobuf/descriptor_pool.py @@ -120,11 +120,13 @@ class DescriptorPool(object): if _USE_C_DESCRIPTORS: - def __new__(cls, descriptor_db=None): - # pylint: disable=protected-access - return descriptor._message.DescriptorPool(descriptor_db) + def __new__(cls, descriptor_db=None): + # pylint: disable=protected-access + return descriptor._message.DescriptorPool(descriptor_db) - def __init__(self, descriptor_db=None): + def __init__( + self, descriptor_db=None, use_deprecated_legacy_json_field_conflicts=False + ): """Initializes a Pool of proto buffs. The descriptor_db argument to the constructor is provided to allow @@ -135,6 +137,8 @@ class DescriptorPool(object): Args: descriptor_db: A secondary source of file descriptors. + use_deprecated_legacy_json_field_conflicts: Unused, for compatibility with + C++. """ self._internal_db = descriptor_database.DescriptorDatabase() diff --git a/python/google/protobuf/pyext/descriptor_pool.cc b/python/google/protobuf/pyext/descriptor_pool.cc index 9388f16c96..6899e94b44 100644 --- a/python/google/protobuf/pyext/descriptor_pool.cc +++ b/python/google/protobuf/pyext/descriptor_pool.cc @@ -155,20 +155,26 @@ static PyDescriptorPool* PyDescriptorPool_NewWithUnderlay( } static PyDescriptorPool* PyDescriptorPool_NewWithDatabase( - DescriptorDatabase* database) { + DescriptorDatabase* database, + bool use_deprecated_legacy_json_field_conflicts) { PyDescriptorPool* cpool = _CreateDescriptorPool(); if (cpool == nullptr) { return nullptr; } + DescriptorPool* pool; if (database != nullptr) { cpool->error_collector = new BuildFileErrorCollector(); - cpool->pool = new DescriptorPool(database, cpool->error_collector); + pool = new DescriptorPool(database, cpool->error_collector); cpool->is_mutable = false; cpool->database = database; } else { - cpool->pool = new DescriptorPool(); + pool = new DescriptorPool(); cpool->is_mutable = true; } + if (use_deprecated_legacy_json_field_conflicts) { + pool->UseDeprecatedLegacyJsonFieldConflicts(); + } + cpool->pool = pool; cpool->is_owned = true; if (!descriptor_pool_map->insert(std::make_pair(cpool->pool, cpool)).second) { @@ -183,6 +189,7 @@ static PyDescriptorPool* PyDescriptorPool_NewWithDatabase( // The public DescriptorPool constructor. static PyObject* New(PyTypeObject* type, PyObject* args, PyObject* kwargs) { + int use_deprecated_legacy_json_field_conflicts = 0; static const char* kwlist[] = {"descriptor_db", nullptr}; PyObject* py_database = nullptr; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O", @@ -193,8 +200,8 @@ static PyObject* New(PyTypeObject* type, if (py_database && py_database != Py_None) { database = new PyDescriptorDatabase(py_database); } - return reinterpret_cast( - PyDescriptorPool_NewWithDatabase(database)); + return reinterpret_cast(PyDescriptorPool_NewWithDatabase( + database, use_deprecated_legacy_json_field_conflicts)); } static void Dealloc(PyObject* pself) {