False positives with typing and linters for async gRPC server using Python

70 Views Asked by At

As can be seen in the hello world example when you implement a gRPC service in Python using the asyncio API you define async def methods. However, the base clase you are extending has non-async methods, like in the base class for the same example. That base class is autogenerated by protoc and I haven't found any options to generate an async base class. As a result I get errors like the following:

  • pylint: W0236: Method 'FooOperation' was expected to be 'non-async', found it instead as 'async' (invalid-overridden-method)
  • mypy: error: Return type "Coroutine[Any, Any, Any]" of "FooOperation" incompatible with return type "Iterator[FooOperationResponse]" in supertype "Foo" [override]

This is not a problem at runtime, and the code works ok. As a workaround, I can disable type checking and linting for those methods by adding the comment # type: ignore # pylint: disable=invalid-overridden-method to each method, but that makes those static analysis less effective. Is there a proper way to do this? Ideally some option or tool so the generated base class uses async methods.

Thanks

0

There are 0 best solutions below