Closed jace closed 4 months ago
Mypy is tripping on the WrappedFunc
and ReturnDecorator
types, casting them to Any
. This affects the requires_roles
and requestargs
(and related) decorators, but a fix is deferred to another PR.
Removing __get__
in the method protocol fixed return type detection, but somehow did not trigger the paramspec mismatch that we were stuck with earlier. Maybe a recent Mypy release fixed it, or maybe it was to do with the self
parameter name in the protocol.
This does not work:
class Method(Protocol[P, R_co]):
def __call__(self, __self: Any, *args: P.args, **kwargs: P.kwargs) -> R_co: ...
However, this works:
class Method(Protocol[P, R_co]):
def __call__(__self, self: Any, *args: P.args, **kwargs: P.kwargs) -> R_co: ...
__get__
and the resulting bound variant of the protocol are not needed.
Solution found at https://github.com/python/typing/discussions/1040. Passes type checking in both Mypy and Pyright.