bblfsh/python-client

Import explodes on Python 3.7

vmarkovtsev opened this issue · 1 comments

import bblfsh.github.com.gogo.protobuf.gogoproto.gogo_pb2

fails with

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.7/site-packages/bblfsh/github/com/gogo/protobuf/gogoproto/gogo_pb2.py", line 670, in <module>
    google_dot_protobuf_dot_descriptor__pb2.EnumOptions.RegisterExtension(goproto_enum_prefix)
  File "/usr/local/lib/python3.7/site-packages/google/protobuf/internal/python_message.py", line 751, in RegisterExtension
    cls.DESCRIPTOR.file.pool.AddExtensionDescriptor(extension_handle)
  File "/usr/local/lib/python3.7/site-packages/google/protobuf/descriptor_pool.py", line 264, in AddExtensionDescriptor
    extension.containing_type.full_name, extension.number))
AssertionError: Extensions "gogoproto.goproto_enum_prefix" and "gogoproto.goproto_enum_prefix" both try to extend message type "google.protobuf.EnumOptions" with field number 62001.

Reproducible exclusively on Python 3.7.0 final (works fine with beta3). How to reproduce:

docker run -it --rm python:3.7.0-stretch bash
pip3 install bblfsh
python3 -c "import bblfsh.github.com.gogo.protobuf.gogoproto.gogo_pb2"

Related to protocolbuffers/protobuf#2533 but not really.

Looks like the top-level import of bblfsh is not visible to the import system and it imports the module twice. The workaround is to comment out that assertion inside protobuf.

Yes, the problem is that import github.com.gogo.protobuf.gogoproto.gogo_pb2 with sweded sys.path and import bblfsh.github.com.gogo.protobuf.gogoproto.gogo_pb2 are different from 3.7's point of view. The solution is to make the internal imports absolute.