Skip to content

Commit

Permalink
clean up some detritus, add signature preservation to inlineCallbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
glyph committed Nov 22, 2022
1 parent d5f4246 commit 06872b2
Showing 1 changed file with 3 additions and 18 deletions.
21 changes: 3 additions & 18 deletions src/twisted/internet/defer.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,7 @@ def _copy_context() -> Type[_NoContext]:


_T = TypeVar("_T")

_ResultParam = TypeVar("_ResultParam", contravariant=True)
_P = ParamSpec("_P")
_R = TypeVar("_R")
_R_co = TypeVar("_R_co", covariant=True)
# https://github.com/python/mypy/issues/11855


class AlreadyCalledError(Exception):
Expand Down Expand Up @@ -1274,14 +1269,6 @@ def main(reactor):
raise NotACoroutineError(f"{coro!r} is not a coroutine")


# _EitherCallback = Callable[[Union[_ResultParam, Failure]], Union[_R_co, Deferred[_R_co]]]
class _EitherCallback(Protocol[_ResultParam, _P, _R_co]):
def __call__(
self, result: Union[_ResultParam, Failure], *args: _P.args, **kwargs: _P.kwargs
) -> Union[_R_co, Deferred[_R_co], Failure]:
...


def ensureDeferred(
coro: Union[
Coroutine[Deferred[_T], Any, _T],
Expand Down Expand Up @@ -2009,11 +1996,9 @@ class _InternalInlineCallbacksCancelledError(Exception):
"""


# type note: "..." is used here because we don't have a better way to express
# that the same arguments are accepted by the returned callable.
def inlineCallbacks(
f: Callable[..., Generator[Deferred[object], object, _T]]
) -> Callable[..., Deferred[_T]]:
f: Callable[_P, Generator[Deferred[object], object, _T]]
) -> Callable[_P, Deferred[_T]]:
"""
L{inlineCallbacks} helps you write L{Deferred}-using code that looks like a
regular sequential function. For example::
Expand Down Expand Up @@ -2074,7 +2059,7 @@ def loadData(url):
"""

@wraps(f)
def unwindGenerator(*args: object, **kwargs: object) -> Deferred[_T]:
def unwindGenerator(*args: _P.args, **kwargs: _P.kwargs) -> Deferred[_T]:
try:
gen = f(*args, **kwargs)
except _DefGen_Return:
Expand Down

0 comments on commit 06872b2

Please sign in to comment.