-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
10155 Add type hints to twisted.internet.task. #1570
Conversation
… that we support, so this extra logic is not needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Thanks!
I don't understand why TypeVar is used , so I only left a comment.
But if this is not reviewed by someone else in 2 weeks, I think that this can be merged.
In the docstring for errback I see
Passing a string as `fail' is deprecated, and will be punished with
a warning message.
I think that t his was already deprecated and maybe can be removed in this PR as a drive by.
| def coiterate( | ||
| self, | ||
| iterator: Iterator[_TaskResultT], | ||
| doneDeferred: Optional[Deferred[Iterator[_TaskResultT]]] = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This (and the return value) should be typed to indicate that the deferred fires with the same-type object as was passed to iterator, rather than just an arbitrary iterator
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you suggest something, cuz I see an iterator of _TaskResultT… that's not specific enough?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wiml poke poke
| @@ -696,7 +711,7 @@ def running(self): | |||
| _theCooperator = Cooperator() | |||
|
|
|||
|
|
|||
| def coiterate(iterator): | |||
| def coiterate(iterator: Iterator[_T]) -> Deferred[Iterator[_T]]: | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as for Cooperator.coiterate()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same question…
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps the question here is whether Iterator[_TaskResultT] used throughout CooperativeTask should instead be a _TaskIteratorT which is defined as TypeVar("_TaskIterableT", bound=Iterator[_TaskResultT]).
I'm not sure that the type of the Iterator (of _TaskResultT) being preserved here is important (that it: part of the API). And I'm not sure if _TaskIteratorT as I suggested above will accomplish that… @graingert: thoughts?
The documentation for coiterate just says that you get back a Deferred that fires on completion, not what that it's return is… so perhaps we should be actually typing return value as Deferred[None]?
Use C{} around symbols in preceeding docstring because I couldn't help myself.
|
I think I've addressed all of the comment except for @wiml's suggestion on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the update.
I think that this can be merged and there is not much use keep it pending without a review.
if someone is not happy with it, we can always have a followup PR.
Thanks again!
|
Thanks |
Add type hints for
twisted.internet.taskContributor Checklist:
tox -e lintto format my patch to meet the Twisted Coding Standard#character).reviewto the keywords field in Trac, and putting a link to this PR in the comment; it shows up in https://twisted.reviews/ now.The first line is automatically generated by GitHub based on PR ID and branch name.
The other lines generated by GitHub should be replaced.