-
Code sample in pyright playground After several attempts I've ended up with this playground, but it still doesn't work as expected: import abc
import typing as t
class Update:
pass
class Abstract(abc.ABC):
async def do_job(self, update: Update) -> None: ...
class InstanceDoerProtocol(t.Protocol):
async def __call__(self, update: Update) -> None: ...
class DoerProtocol(t.Protocol):
async def __call__(self_, self: Abstract, update: Update) -> None: # type: ignore[reportSelfClsParameterName]
...
@t.overload
def __get__(self, instance: Abstract, owner: type[Abstract] | None = None) -> InstanceDoerProtocol: ...
@t.overload
def __get__(self, instance: None, owner: type[Abstract] | None = None) -> "DoerProtocol": ...
def __get__(self, instance: Abstract | None, owner: type[Abstract] | None = None) -> t.Union[InstanceDoerProtocol, "DoerProtocol"]:
...
def decorator(func: DoerProtocol) -> DoerProtocol:
async def __internal(self: Abstract, update: Update) -> None:
await func(self, update)
return __internal
class Impl(Abstract):
@decorator
async def do_job(self, update: Update) -> None:
pass |
Beta Was this translation helpful? Give feedback.
Answered by
bschnurr
Aug 12, 2024
Replies: 1 comment 2 replies
-
see https://microsoft.github.io/pyright/#/typed-libraries?id=annotating-decorators |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
belegnar
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
see https://microsoft.github.io/pyright/#/typed-libraries?id=annotating-decorators