shabbyrobe / grpc-stubs

gRPC typing stubs for Python
MIT License
35 stars 21 forks source link

The partial typing of the aio.pyi module causes an error #35

Closed Roktober closed 1 year ago

Roktober commented 1 year ago

Description of issue

If you turn to pep561, which describes how to use partially typed stubs, it says

Type checkers should merge the stub package and runtime package or typeshed directories. This can be thought of as the functional equivalent of copying the stub package into the same directory as the corresponding runtime package or typeshed folder and type checking the combined directory structure. Thus type checkers MUST maintain the normal resolution order of checking .pyi before .py files.

This means that the typing file is used to fully type the package, and even if the package is typed, it is not used in type resolution. Which makes it impossible to use the package when developing with aio.

But everything works fine on the version 1.24.11

Minimum Reproducible Example

python version 3.11 grpc-stubs==1.24.12.1 grpcio-reflection==1.42.0 grpcio-tools==1.42.0 grpcio==1.42.0 protobuf==3.19.6

from grpc.aio import (
    UnaryUnaryClientInterceptor,
    UnaryStreamClientInterceptor,
    StreamUnaryClientInterceptor,
    StreamStreamClientInterceptor,
    AioRpcError,
    ClientCallDetails,
    Channel,
    Server,
    ServicerContext,
)
issue.py:1: error: Module "grpc.aio" has no attribute "UnaryUnaryClientInterceptor"; maybe "ClientInterceptor"?  [attr-defined]
issue.py:1: error: Module "grpc.aio" has no attribute "UnaryStreamClientInterceptor"; maybe "ClientInterceptor"?  [attr-defined]
issue.py:1: error: Module "grpc.aio" has no attribute "StreamUnaryClientInterceptor"; maybe "ClientInterceptor"?  [attr-defined]
issue.py:1: error: Module "grpc.aio" has no attribute "StreamStreamClientInterceptor"  [attr-defined]
issue.py:1: error: Module "grpc.aio" has no attribute "AioRpcError"  [attr-defined]
issue.py:1: error: Module "grpc.aio" has no attribute "ClientCallDetails"  [attr-defined]
shabbyrobe commented 1 year ago

What's the solution here? Does the aio py.typed file need to provide types for every symbol?

Roktober commented 1 year ago

Yes, a possible solution could be a separate versioning for the package, until aio is fully implemented. For example with postfix Alpha. Also the current version of the package does not match the semver

shabbyrobe commented 1 year ago

Yes, a possible solution could be a separate versioning for the package, until aio is fully implemented. For example with postfix Alpha

Thanks. I think I'll see if I can fill in the blanks in the aio now lib now, and if that's too hard I'll pull it back out into a a PR.

Also the current version of the package does not match the semver

Are you referring to the four segments? If so, that is intentional. The first three segments will track with the upstream grpc library (soon to be updated as I have recently brought the non-aio stubs up to speed) and the fourth will track the typing version within that.

The next version, regardless of which way I end up going with aio, will be 1.53.0.1.

shabbyrobe commented 1 year ago

I have a PR here that adds the missing types: https://github.com/shabbyrobe/grpc-stubs/pull/36. It works with your MRE. Thank you for providing it, it made it much easier to deal with the issue.

I'll release it shortly. Please let me know if it causes you issues.