Skip to content

bpo-38192: Fix remaining passing of "loop" in the protocol examples#16202

Merged
miss-islington merged 3 commits into
python:masterfrom
hniksic:bpo-38178-followup
Sep 17, 2019
Merged

bpo-38192: Fix remaining passing of "loop" in the protocol examples#16202
miss-islington merged 3 commits into
python:masterfrom
hniksic:bpo-38178-followup

Conversation

@hniksic
Copy link
Copy Markdown
Contributor

@hniksic hniksic commented Sep 16, 2019

Copy link
Copy Markdown
Contributor

@aeros aeros 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 PR @hniksic.

Since this is just removing the explicit passing of loop which was is going to be receiving deprecation warnings in 3.8 for several parts of the public API, this looks correct for the most part. The consensus from the asyncio experts seems to be that there is no need for loop to be explicitly passed.

The only suggestion I would make is to modify the ordering within main() (line 949) and removing the comment where the future is created.
Current:

async def main():
    # Get a reference to the event loop as we plan to use
    # low-level APIs.
    loop = asyncio.get_running_loop()

    # Create a pair of connected sockets
    rsock, wsock = socket.socketpair()

    # Prepare a future to inform us when the connection is closed.
    on_con_lost = loop.create_future()

Suggested:

async def main():
    # Get a reference to the event loop as we plan to use
    # low-level APIs.
    loop = asyncio.get_running_loop()
    on_con_lost = loop.create_future()

    # Create a pair of connected sockets
    rsock, wsock = socket.socketpair()

It makes more sense to set up on_con_lost = loop.create_future() right after acquiring a reference to the event loop, rather than after creating the pair of sockets. Even if it provides the same effect functionally, this makes the coroutine's structuring more logical.

The removal of the comment might be a bit more subjective, but personally I don't think it provides additional insight. Especially since it wasn't seen as necessary when it was used in the previous two examples, I don't think it's needed for this one either.

But, we can wait for feedback from @asvetlov and @1st1 before moving forward with the suggested changes.

@hniksic
Copy link
Copy Markdown
Contributor Author

hniksic commented Sep 17, 2019

@aeros167 Thanks for the review. I like your suggestion and have updated the PR.

@hniksic hniksic changed the title bpo-38192: Fix remaining passing of "loop" in the docs bpo-38192: Fix remaining passing of "loop" in the protocol examples Sep 17, 2019
Copy link
Copy Markdown
Contributor

@asvetlov asvetlov left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@miss-islington
Copy link
Copy Markdown
Contributor

Thanks @hniksic for the PR 🌮🎉.. I'm working now to backport this PR to: 3.7, 3.8.
🐍🍒⛏🤖

@bedevere-bot
Copy link
Copy Markdown

GH-16218 is a backport of this pull request to the 3.8 branch.

@bedevere-bot
Copy link
Copy Markdown

GH-16219 is a backport of this pull request to the 3.7 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Sep 17, 2019
miss-islington added a commit that referenced this pull request Sep 17, 2019
miss-islington added a commit that referenced this pull request Sep 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation in the Doc dir skip news topic-asyncio

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants