Function is not valid as a type
See original GitHub issueHi,
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:
- Created 4 years ago
- Reactions:3
- Comments:5 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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).
@nipunn1313, #112 looks like it will cover these above cases. Thanks for the quick turnaround!