Skip to content

Couldn't build proto file into descriptor pool [Python 3.13] #490

Closed
@cdce8p

Description

@cdce8p

Encountered this issue while testing Python 3.13.0rc2. To reproduce

import proto

__protobuf__ = proto.module(
    package="some_module",
    manifest={"View", "Encoding"},
)

class View(proto.Enum):
    A = 0

class Encoding(proto.Enum):
    B = 0
$ python test.py
Traceback (most recent call last):
  File "/.../proto-plus-python/test.py", line 11, in <module>
    class Encoding(proto.Enum):
        B = 0
  File "/.../proto-plus-python/proto/enums.py", line 105, in __new__
    file_info.generate_file_pb(new_class=cls, fallback_salt=full_name)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/.../proto-plus-python/proto/_file_info.py", line 104, in generate_file_pb
    pool.Add(self.descriptor)
    ~~~~~~~~^^^^^^^^^^^^^^^^^
TypeError: Couldn't build proto file into descriptor pool: duplicate symbol 'some_module.__firstlineno__'
$ pip list
Package    Version
---------- -------
pip        24.2
proto-plus 1.24.0
protobuf   5.28.2

--
AFAICT the issue shows up as soon as two proto.Enum are defined in one module. A quick experiment suggests that the reason might be here

value=sorted(
(
descriptor_pb2.EnumValueDescriptorProto(name=name, number=number)
# Minor hack to get all the enum variants out.
for name, number in attrs.items()
if isinstance(number, int)
),

The attributes are only filtered by if isinstance(number, int). Python 3.13 added the new __firstlineno__ attribute which is an integer and as such not filtered as it should be. Just changing the condition here would be enough to resolve it, just not sure that's the best option as I'm unfamiliar with the code base.

-if isinstance(number, int)
+if isinstance(number, int) and name != "__firstlineno__"

Metadata

Metadata

Assignees

Labels

priority: p2Moderately-important priority. Fix may not be included in next release.status: investigatingThe issue is under investigation, which is determined to be non-trivial.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions