Skip to content

Commit c51f111

Browse files
anandoleecopybara-github
authored andcommitted
BREAKING CHANGE in v26: Remove Deprecated APIs that add non top descriptor.
Include AddFileDescriptor, AddDescriptor, AddEnumDescriptor, AddExtensionDescriptor, AddServiceDescriptor. Those Deprecated APIs may add unlinked descriptors to descriptor_pool which is is wrong. Should use Add() or AddSerializedFile() instead. Those APIs were raising deprecated warnings since 2019 PiperOrigin-RevId: 595831718
1 parent 181bcee commit c51f111

File tree

2 files changed

+0
-143
lines changed

2 files changed

+0
-143
lines changed

python/google/protobuf/descriptor_pool.py

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,6 @@
4747
_USE_C_DESCRIPTORS = descriptor._USE_C_DESCRIPTORS # pylint: disable=protected-access
4848

4949

50-
def _Deprecated(func):
51-
"""Mark functions as deprecated."""
52-
53-
def NewFunc(*args, **kwargs):
54-
warnings.warn(
55-
'Call to deprecated function %s(). Note: Do add unlinked descriptors '
56-
'to descriptor_pool is wrong. Please use Add() or AddSerializedFile() '
57-
'instead. This function will be removed soon.' % func.__name__,
58-
category=DeprecationWarning)
59-
return func(*args, **kwargs)
60-
NewFunc.__name__ = func.__name__
61-
NewFunc.__doc__ = func.__doc__
62-
NewFunc.__dict__.update(func.__dict__)
63-
return NewFunc
64-
65-
6650
def _NormalizeFullyQualifiedName(name):
6751
"""Remove leading period from fully-qualified type name.
6852
@@ -207,12 +191,6 @@ def AddSerializedFile(self, serialized_file_desc_proto):
207191
file_desc.serialized_pb = serialized_file_desc_proto
208192
return file_desc
209193

210-
# Add Descriptor to descriptor pool is deprecated. Please use Add()
211-
# or AddSerializedFile() to add a FileDescriptorProto instead.
212-
@_Deprecated
213-
def AddDescriptor(self, desc):
214-
self._AddDescriptor(desc)
215-
216194
# Never call this method. It is for internal usage only.
217195
def _AddDescriptor(self, desc):
218196
"""Adds a Descriptor to the pool, non-recursively.
@@ -267,12 +245,6 @@ def _AddEnumDescriptor(self, enum_desc):
267245
self._top_enum_values[full_name] = enum_value
268246
self._AddFileDescriptor(enum_desc.file)
269247

270-
# Add ServiceDescriptor to descriptor pool is deprecated. Please use Add()
271-
# or AddSerializedFile() to add a FileDescriptorProto instead.
272-
@_Deprecated
273-
def AddServiceDescriptor(self, service_desc):
274-
self._AddServiceDescriptor(service_desc)
275-
276248
# Never call this method. It is for internal usage only.
277249
def _AddServiceDescriptor(self, service_desc):
278250
"""Adds a ServiceDescriptor to the pool.
@@ -288,12 +260,6 @@ def _AddServiceDescriptor(self, service_desc):
288260
service_desc.file.name)
289261
self._service_descriptors[service_desc.full_name] = service_desc
290262

291-
# Add ExtensionDescriptor to descriptor pool is deprecated. Please use Add()
292-
# or AddSerializedFile() to add a FileDescriptorProto instead.
293-
@_Deprecated
294-
def AddExtensionDescriptor(self, extension):
295-
self._AddExtensionDescriptor(extension)
296-
297263
# Never call this method. It is for internal usage only.
298264
def _AddExtensionDescriptor(self, extension):
299265
"""Adds a FieldDescriptor describing an extension to the pool.
@@ -343,10 +309,6 @@ def _AddExtensionDescriptor(self, extension):
343309
python_message._AttachFieldHelpers(
344310
extension.containing_type._concrete_class, extension)
345311

346-
@_Deprecated
347-
def AddFileDescriptor(self, file_desc):
348-
self._InternalAddFileDescriptor(file_desc)
349-
350312
# Never call this method. It is for internal usage only.
351313
def _InternalAddFileDescriptor(self, file_desc):
352314
"""Adds a FileDescriptor to the pool, non-recursively.

python/google/protobuf/pyext/descriptor_pool.cc

Lines changed: 0 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -482,100 +482,6 @@ static PyObject* FindAllExtensions(PyObject* self, PyObject* arg) {
482482
return result.release();
483483
}
484484

485-
// These functions should not exist -- the only valid way to create
486-
// descriptors is to call Add() or AddSerializedFile().
487-
// But these AddDescriptor() functions were created in Python and some people
488-
// call them, so we support them for now for compatibility.
489-
// However we do check that the existing descriptor already exists in the pool,
490-
// which appears to always be true for existing calls -- but then why do people
491-
// call a function that will just be a no-op?
492-
// TODO: Need to investigate further.
493-
494-
static PyObject* AddFileDescriptor(PyObject* self, PyObject* descriptor) {
495-
const FileDescriptor* file_descriptor =
496-
PyFileDescriptor_AsDescriptor(descriptor);
497-
if (!file_descriptor) {
498-
return nullptr;
499-
}
500-
if (file_descriptor !=
501-
reinterpret_cast<PyDescriptorPool*>(self)->pool->FindFileByName(
502-
file_descriptor->name())) {
503-
PyErr_Format(PyExc_ValueError,
504-
"The file descriptor %s does not belong to this pool",
505-
file_descriptor->name().c_str());
506-
return nullptr;
507-
}
508-
Py_RETURN_NONE;
509-
}
510-
511-
static PyObject* AddDescriptor(PyObject* self, PyObject* descriptor) {
512-
const Descriptor* message_descriptor =
513-
PyMessageDescriptor_AsDescriptor(descriptor);
514-
if (!message_descriptor) {
515-
return nullptr;
516-
}
517-
if (message_descriptor !=
518-
reinterpret_cast<PyDescriptorPool*>(self)->pool->FindMessageTypeByName(
519-
message_descriptor->full_name())) {
520-
PyErr_Format(PyExc_ValueError,
521-
"The message descriptor %s does not belong to this pool",
522-
message_descriptor->full_name().c_str());
523-
return nullptr;
524-
}
525-
Py_RETURN_NONE;
526-
}
527-
528-
static PyObject* AddEnumDescriptor(PyObject* self, PyObject* descriptor) {
529-
const EnumDescriptor* enum_descriptor =
530-
PyEnumDescriptor_AsDescriptor(descriptor);
531-
if (!enum_descriptor) {
532-
return nullptr;
533-
}
534-
if (enum_descriptor !=
535-
reinterpret_cast<PyDescriptorPool*>(self)->pool->FindEnumTypeByName(
536-
enum_descriptor->full_name())) {
537-
PyErr_Format(PyExc_ValueError,
538-
"The enum descriptor %s does not belong to this pool",
539-
enum_descriptor->full_name().c_str());
540-
return nullptr;
541-
}
542-
Py_RETURN_NONE;
543-
}
544-
545-
static PyObject* AddExtensionDescriptor(PyObject* self, PyObject* descriptor) {
546-
const FieldDescriptor* extension_descriptor =
547-
PyFieldDescriptor_AsDescriptor(descriptor);
548-
if (!extension_descriptor) {
549-
return nullptr;
550-
}
551-
if (extension_descriptor !=
552-
reinterpret_cast<PyDescriptorPool*>(self)->pool->FindExtensionByName(
553-
extension_descriptor->full_name())) {
554-
PyErr_Format(PyExc_ValueError,
555-
"The extension descriptor %s does not belong to this pool",
556-
extension_descriptor->full_name().c_str());
557-
return nullptr;
558-
}
559-
Py_RETURN_NONE;
560-
}
561-
562-
static PyObject* AddServiceDescriptor(PyObject* self, PyObject* descriptor) {
563-
const ServiceDescriptor* service_descriptor =
564-
PyServiceDescriptor_AsDescriptor(descriptor);
565-
if (!service_descriptor) {
566-
return nullptr;
567-
}
568-
if (service_descriptor !=
569-
reinterpret_cast<PyDescriptorPool*>(self)->pool->FindServiceByName(
570-
service_descriptor->full_name())) {
571-
PyErr_Format(PyExc_ValueError,
572-
"The service descriptor %s does not belong to this pool",
573-
service_descriptor->full_name().c_str());
574-
return nullptr;
575-
}
576-
Py_RETURN_NONE;
577-
}
578-
579485
// The code below loads new Descriptors from a serialized FileDescriptorProto.
580486
static PyObject* AddSerializedFile(PyObject* pself, PyObject* serialized_pb) {
581487
PyDescriptorPool* self = reinterpret_cast<PyDescriptorPool*>(pself);
@@ -689,17 +595,6 @@ static PyMethodDef Methods[] = {
689595
{"SetFeatureSetDefaults", SetFeatureSetDefaults, METH_O,
690596
"Sets the default feature mappings used during the build."},
691597

692-
{"AddFileDescriptor", AddFileDescriptor, METH_O,
693-
"No-op. Add() must have been called before."},
694-
{"AddDescriptor", AddDescriptor, METH_O,
695-
"No-op. Add() must have been called before."},
696-
{"AddEnumDescriptor", AddEnumDescriptor, METH_O,
697-
"No-op. Add() must have been called before."},
698-
{"AddExtensionDescriptor", AddExtensionDescriptor, METH_O,
699-
"No-op. Add() must have been called before."},
700-
{"AddServiceDescriptor", AddServiceDescriptor, METH_O,
701-
"No-op. Add() must have been called before."},
702-
703598
{"FindFileByName", FindFileByName, METH_O,
704599
"Searches for a file descriptor by its .proto name."},
705600
{"FindMessageTypeByName", FindMessageByName, METH_O,

0 commit comments

Comments
 (0)