8000 Function is not valid as a type · Issue #108 · nipunn1313/mypy-protobuf · GitHub
[go: up one dir, main page]

Skip to content
Function is not valid as a type #108
@forestbelton

Description

@forestbelton

Hi,

Thank you for this wonderful project. I'm integrating mypy with a codebase that uses protobufs and feel that this will be quite helpful in doing so!

I'm able to generate the *.pyi type stub files along with the other definitions by invoking the following command:

$ python -m grpc_tools.protoc -I=github.com/gogo/protobuf/gogoproto -I=. \
    --python_out=generated/python \
    --grpc_python_out=generated/python \
    --mypy_out=generated/python

The generated *.pyi files look correct, however when I try to run mypy over modules that import these definitions, I receive error messages like the following (names/line #s scrubbed):

generated/python/foo_pb2.pyi:123: error: Function "Foo" is not valid as a type
generated/python/foo_pb2.pyi:123: note: Perhaps you need "Callable[...]" or a callback protocol?

Inside of foo_pb2.py, Foo is defined like follows:

Foo = _reflection.GeneratedProtocolMessageType('Foo', (_message.Message,), {
  'DESCRIPTOR' : _FOO,
  '__module__' : 'path.to.foo'
  # @@protoc_insertion_point(class_scope:Foo)
  })
_sym_db.RegisterMessage(Foo)

Is there something obvious I'm doing wrong? I'm using the following versions for my dependencies:

  • mypy 0.761
  • mypy-protobuf 1.18
  • Python 3.6.5
  • python-protobuf 3.11.3
$ python -m grpc_tools.protoc --version
libprotoc 3.8.0

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0