Skip to content

Commit

Permalink
Add type hints to twisted.internet.task.
Browse files Browse the repository at this point in the history
  • Loading branch information
wsanchez committed Mar 27, 2021
1 parent 083c1c3 commit fadb582
Show file tree
Hide file tree
Showing 6 changed files with 191 additions and 145 deletions.
5 changes: 0 additions & 5 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,6 @@ check_untyped_defs = False
allow_untyped_defs = True
check_untyped_defs = False

[mypy-twisted.internet.task]
allow_untyped_defs = True
check_untyped_defs = False
allow_incomplete_defs = True

[mypy-twisted.internet.tcp]
allow_untyped_defs = True
check_untyped_defs = False
Expand Down
18 changes: 10 additions & 8 deletions src/twisted/internet/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
AnyStr,
Callable,
Dict,
Iterable,
List,
Mapping,
NewType,
Expand Down Expand Up @@ -237,13 +238,14 @@ def __repr__(self) -> str:
if hasattr(self, "func"):
# This code should be replaced by a utility function in reflect;
# see ticket #6066:
if hasattr(self.func, "__qualname__"):
func: Optional[str] = self.func.__qualname__
elif hasattr(self.func, "__name__"):
func = self.func.func_name # type: ignore[attr-defined]
if hasattr(self.func, "im_class"):
func = self.func.im_class.__name__ + "." + func # type: ignore[attr-defined]
else:
func = getattr(self.func, "__qualname__", None)
if func is None:
func = getattr(self.func, "__name__", None)
if func is not None:
imClass = getattr(self.func, "im_class", None)
if imClass is not None:
func = f"{imClass}.{func}"
if func is None:
func = reflect.safe_repr(self.func)
else:
func = None
Expand Down Expand Up @@ -907,7 +909,7 @@ def _moveCallLaterSooner(self, delayedCall: DelayedCall) -> None:
def _cancelCallLater(self, delayedCall: DelayedCall) -> None:
self._cancellations += 1

def getDelayedCalls(self) -> List[IDelayedCall]:
def getDelayedCalls(self) -> Iterable[IDelayedCall]:
"""
Return all the outstanding delayed calls in the system.
They are returned in no particular order.
Expand Down
2 changes: 1 addition & 1 deletion src/twisted/internet/defer.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ def chainDeferred(self, d: "Deferred[_DeferredResultT]") -> "Deferred[None]":
d._chainedTo = self
return self.addCallbacks(d.callback, d.errback)

def callback(self, result: _DeferredResultT) -> None:
def callback(self, result: Union[_DeferredResultT, Failure]) -> None:
"""
Run all success callbacks that have been added to this L{Deferred}.
Expand Down
4 changes: 2 additions & 2 deletions src/twisted/internet/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -1194,11 +1194,11 @@ def callLater(
C{reset()} methods.
"""

def getDelayedCalls() -> List["IDelayedCall"]:
def getDelayedCalls() -> Iterable["IDelayedCall"]:
"""
Retrieve all currently scheduled delayed calls.
@return: A list of L{IDelayedCall} providers representing all
@return: An iterable of L{IDelayedCall} providers representing all
currently scheduled calls. This is everything that has been
returned by C{callLater} but not yet called or cancelled.
"""
Expand Down
Loading

0 comments on commit fadb582

Please sign in to comment.