Giter Site home page Giter Site logo

Comments (2)

bkeryan avatar bkeryan commented on July 19, 2024 1

Hi @macro1,

Thanks for the heads up.

According to the linked documentation, intercept_service is allowed to return None. It is not required to raise an exception when the intercepted service returns None.

The return type in the example was copied from grpc-stubs. At the time I filed this issue, grpc-stubs annotated intercept_service with a return type of grpc.RpcMethodHandler[grpc.TRequest, grpc.TResponse]. It has since been fixed by #43, which added typing.Optional to the return type.

from grpc-stubs.

macro1 avatar macro1 commented on July 19, 2024

hi @bkeryan. the issue isn't the library in this case.

the return type you have defined for continuation is typing.Optional[grpc.RpcMethodHandler[grpc.TRequest, grpc.TResponse]], which means returning it directly would violate the return type you've defined for intercept_service()

one way to demonstrate this is to raise an exception when the value is None, this will cause the typing to work out:

class NullServerInterceptor(grpc.ServerInterceptor[grpc.TRequest, grpc.TResponse]):
    def intercept_service(
        self,
        continuation: Callable[
            [grpc.HandlerCallDetails],
            Optional[grpc.RpcMethodHandler[grpc.TRequest, grpc.TResponse]]
        ],
        handler_call_details: grpc.HandlerCallDetails,
    ) -> grpc.RpcMethodHandler[grpc.TRequest, grpc.TResponse]:
        response = continuation(handler_call_details)
        if response is None:
            raise NotImplementedError
        return response

from grpc-stubs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.