Skip to content
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

Merged
merged 16 commits into from
May 10, 2021
Merged

Conversation

wsanchez
Copy link
Member

@wsanchez wsanchez commented Mar 27, 2021

Add type hints for twisted.internet.task

Contributor Checklist:

  • The associated ticket in Trac is here: https://twistedmatrix.com/trac/ticket/10155
  • I ran tox -e lint to format my patch to meet the Twisted Coding Standard
  • I have created a newsfragment in src/twisted/newsfragments/ (see: News files)
  • The title of the PR starts with the associated Trac ticket number (without the # character).
  • I have updated the automated tests and checked that all checks for the PR are green.
  • I have submitted the associated Trac ticket for review by adding the word review to the keywords field in Trac, and putting a link to this PR in the comment; it shows up in https://twisted.reviews/ now.
  • The merge commit will use the below format
    The first line is automatically generated by GitHub based on PR ID and branch name.
    The other lines generated by GitHub should be replaced.
Merge pull request #123 from twisted/4356-branch-name-with-trac-id

Author: <github_username>, <github_usernames_if_more_authors>
Reviewer: <github_username>, <github_username_if_more_reviewers>
Fixes: ticket:<trac_ticket_number>, ticket:<another_if_more_in_one_PR>

Long description providing a summary of these changes.
(as long as you wish)

@wsanchez wsanchez self-assigned this Mar 27, 2021
src/twisted/internet/base.py Outdated Show resolved Hide resolved
@wsanchez wsanchez requested a review from a team April 4, 2021 18:27
Copy link
Member

@adiroiban adiroiban left a 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.

src/twisted/internet/defer.py Show resolved Hide resolved
src/twisted/internet/task.py Outdated Show resolved Hide resolved
src/twisted/internet/task.py Show resolved Hide resolved
src/twisted/internet/task.py Outdated Show resolved Hide resolved
src/twisted/internet/task.py Show resolved Hide resolved
@adiroiban adiroiban requested a review from a team April 6, 2021 00:11
wiml
wiml previously requested changes Apr 9, 2021
src/twisted/internet/base.py Outdated Show resolved Hide resolved
src/twisted/internet/defer.py Show resolved Hide resolved
src/twisted/internet/interfaces.py Outdated Show resolved Hide resolved
src/twisted/internet/task.py Outdated Show resolved Hide resolved
src/twisted/internet/task.py Show resolved Hide resolved
def coiterate(
self,
iterator: Iterator[_TaskResultT],
doneDeferred: Optional[Deferred[Iterator[_TaskResultT]]] = None,
Copy link
Contributor

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

Copy link
Member Author

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wiml poke poke

src/twisted/internet/task.py Show resolved Hide resolved
@@ -696,7 +711,7 @@ def running(self):
_theCooperator = Cooperator()


def coiterate(iterator):
def coiterate(iterator: Iterator[_T]) -> Deferred[Iterator[_T]]:
Copy link
Contributor

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()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question…

Copy link
Member Author

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]?

src/twisted/internet/task.py Show resolved Hide resolved
src/twisted/internet/task.py Show resolved Hide resolved
@wsanchez
Copy link
Member Author

I think I've addressed all of the comment except for @wiml's suggestion on coiterate, since I'm not sure what to change there.

@wsanchez wsanchez requested review from wiml and adiroiban April 26, 2021 22:28
Copy link
Member

@adiroiban adiroiban left a 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!

@wsanchez wsanchez dismissed wiml’s stale review May 10, 2021 10:10

addressable later

@wsanchez wsanchez merged commit e0c069b into trunk May 10, 2021
@wsanchez
Copy link
Member Author

Thanks

@wsanchez wsanchez deleted the 10155-mypy-task branch May 10, 2021 10:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants