mirror of
https://github.com/protocolbuffers/protobuf
synced 2026-08-26 02:23:14 -04:00
Change Python DescriptorDatabase FindFileContainingSymbol() to accept leading "." to match DescriptorPool and other languages
PiperOrigin-RevId: 929451066
This commit is contained in:
parent
7caffc11ee
commit
e86e536349
2 changed files with 7 additions and 13 deletions
|
|
@ -120,14 +120,7 @@ class DescriptorDatabase(object):
|
|||
Raises:
|
||||
KeyError if no file contains the specified symbol.
|
||||
"""
|
||||
if symbol.count('.') == 1 and symbol[0] == '.':
|
||||
symbol = symbol.lstrip('.')
|
||||
warnings.warn(
|
||||
'Please remove the leading "." when '
|
||||
'FindFileContainingSymbol, this will turn to error '
|
||||
'in 2026 Jan.',
|
||||
RuntimeWarning,
|
||||
)
|
||||
symbol = symbol.lstrip('.')
|
||||
try:
|
||||
return self._file_desc_protos_by_symbol[symbol]
|
||||
except KeyError:
|
||||
|
|
|
|||
|
|
@ -95,6 +95,12 @@ class DescriptorDatabaseTest(unittest.TestCase):
|
|||
'google.protobuf.python.internal.FACTORY_2_VALUE_0'
|
||||
),
|
||||
)
|
||||
self.assertEqual(
|
||||
file_desc_proto,
|
||||
db.FindFileContainingSymbol(
|
||||
'.google.protobuf.python.internal.FACTORY_2_VALUE_0'
|
||||
),
|
||||
)
|
||||
self.assertEqual(
|
||||
file_desc_proto2, db.FindFileContainingSymbol('NO_PACKAGE_VALUE_0')
|
||||
)
|
||||
|
|
@ -150,11 +156,6 @@ class DescriptorDatabaseTest(unittest.TestCase):
|
|||
with self.assertRaisesRegex(KeyError, r'\'proto2_unittest\.NoneMessage\''):
|
||||
db.FindFileContainingSymbol('proto2_unittest.NoneMessage')
|
||||
|
||||
with self.assertRaises(KeyError):
|
||||
db.FindFileContainingSymbol(
|
||||
'.google.protobuf.python.internal.FACTORY_2_VALUE_0'
|
||||
)
|
||||
|
||||
def testConflictRegister(self):
|
||||
db = descriptor_database.DescriptorDatabase()
|
||||
unittest_fd = descriptor_pb2.FileDescriptorProto.FromString(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue