question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Function is not valid as a type

See original GitHub issue

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!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
nipunn1313commented, Feb 24, 2020

@forestbelton - mind taking a look at #112 to see if it handles the case you’ve brought up here (There are tests which should help illustrate).

0reactions
forestbeltoncommented, Feb 25, 2020

@nipunn1313, #112 looks like it will cover these above cases. Thanks for the quick turnaround!

Read more comments on GitHub >

github_iconTop Results From Across the Web

mypy "is not valid as a type" for types constructed with `type()`
In my use case I have a class factory function that returns a class ( var=class_factory() ). This was the only approach I...
Read more >
dynamic base class "error: Variable ... is not valid as a type ...
dynamic base class "error: Variable ... is not valid as a type" when it is the parameter to a function and typed as...
Read more >
Common issues and solutions - mypy 0.991 documentation
The reason is that if the type of a is unknown, the type of a.split() is also unknown, so it is inferred as...
Read more >
83. ATTEMPT TO USE A FUNCTION THAT IS NOT VALID IN A ...
You will receive this error message if you attempt to use such functions in a model's constraints or objective function.
Read more >
TypeError: "x" is not a function - JavaScript - MDN Web Docs
The JavaScript exception "is not a function" occurs when there was an attempt to call a value from a function, but the value...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found