Skip to content

bpo-34728: Remove deprecate *loop* argument in asyncio.sleep#9415

Merged
willingc merged 7 commits intopython:masterfrom
joaojunior:remove-loop-argument-in-sleep
Sep 24, 2018
Merged

bpo-34728: Remove deprecate *loop* argument in asyncio.sleep#9415
willingc merged 7 commits intopython:masterfrom
joaojunior:remove-loop-argument-in-sleep

Conversation

@joaojunior
Copy link
Copy Markdown
Contributor

@joaojunior joaojunior commented Sep 19, 2018

Warn deprecate argument loop in asyncio.sleep, asyncio.wait and asyncio.wait_for. Also change calls for get_event_loop() to calls for get_running_loop() in these methods.

https://bugs.python.org/issue34728

@the-knights-who-say-ni
Copy link
Copy Markdown

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA).

Unfortunately we couldn't find an account corresponding to your GitHub username on bugs.python.org (b.p.o) to verify you have signed the CLA (this might be simply due to a missing "GitHub Name" entry in your b.p.o account settings). This is necessary for legal reasons before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

You can check yourself to see if the CLA has been received.

Thanks again for your contribution, we look forward to reviewing it!

@joaojunior joaojunior changed the title bpo34728: Remove deprecate *loop* argument in asyncio.sleep bpo-34728: Remove deprecate *loop* argument in asyncio.sleep Sep 19, 2018
Comment thread Lib/asyncio/tasks.py Outdated
Copy link
Copy Markdown
Contributor

@fbidu fbidu Sep 19, 2018

Choose a reason for hiding this comment

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

I think that just removing the loop argument may be bad for compatibility reasons. Perhaps it is better to catch the argument and raise an DeprecationWarning, as proposed in the issue

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@fbidu very good. I will change for this and send the PR again. Thank you for your review.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, @fbidu is right.

@joaojunior joaojunior force-pushed the remove-loop-argument-in-sleep branch from a015623 to db2c478 Compare September 20, 2018 09:39
@joaojunior
Copy link
Copy Markdown
Contributor Author

joaojunior commented Sep 20, 2018

Hi @fbidu and @1st1 I fix here. Also, I add test for this.
When I run all tests in my machine, it works. When run in the CI, doesn't work. Could you help me?

Comment thread Lib/test/test_asyncio/test_tasks.py Outdated
self.assertEqual(result, 11)

def test_loop_argument_is_deprecated(self):
"""
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Use a regular comment for this, not a docstring.

Comment thread Lib/test/test_asyncio/test_tasks.py Outdated
will be removed
"""
with self.assertWarns(DeprecationWarning):
self.loop.run_until_complete(asyncio.wait_for(coroutine_function(),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Weird formatting, I'd do this:

self.loop.run_until_complete(
    asyncio.wait_for(coroutine_function(), 0.01, loop=self.loop))

@1st1
Copy link
Copy Markdown
Member

1st1 commented Sep 20, 2018

When I run all tests in my machine, it works. When run in the CI, doesn't work. Could you help me?

Looks like CI failures are unrelated to this PR.

@joaojunior
Copy link
Copy Markdown
Contributor Author

@1st1 Could you check again?

@1st1
Copy link
Copy Markdown
Member

1st1 commented Sep 20, 2018

Please add a news entry using blurb

@joaojunior
Copy link
Copy Markdown
Contributor Author

@1st1 It is my first contribution in Python. :-)
Thank you for your help and comments.

@1st1
Copy link
Copy Markdown
Member

1st1 commented Sep 20, 2018

@asvetlov please take a look too.

@joaojunior BTW, I think we can also replace get_event_loop() calls with get_running_loop().

@joaojunior
Copy link
Copy Markdown
Contributor Author

@1st1 Very good. I will change and run the tests to verify.

Copy link
Copy Markdown
Contributor

@willingc willingc left a comment

Choose a reason for hiding this comment

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

Thanks @joaojunior for this PR. I've made some small style suggestions should you wish to add them to the PR.

@@ -0,0 +1,2 @@
Add warn when deprecate argument `loop` is used in methods: `asyncio.sleep`,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Perhaps a bit clearer: Add deprecation warning when loop is used ...

Comment thread Lib/test/test_asyncio/test_tasks.py Outdated
self.assertEqual(result, 11)

def test_loop_argument_is_deprecated(self):
# this test should be removed in Python 4.0 when the loop argument
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If possible, would you like to shorten the 2 line comment to 1 line in these tests?

Suggestion: Remove test when loop argument is removed in Python 4.0

Thanks for writing tests 😄

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hi @willingc Thanks for your comments. I will change now.

@joaojunior
Copy link
Copy Markdown
Contributor Author

@willingc Thank you for your suggestions and help. I already change.

Copy link
Copy Markdown
Contributor

@willingc willingc 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 for making the updates @joaojunior

@willingc willingc merged commit 558c49b into python:master Sep 24, 2018
@joaojunior joaojunior deleted the remove-loop-argument-in-sleep branch September 24, 2018 10:03
Comment thread Lib/asyncio/tasks.py
loop = events.get_event_loop()
loop = events.get_running_loop()
else:
warnings.warn("The loop argument is deprecated and scheduled for"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All of the warning messages are missing spaces (between "for" and "removal").

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You're right. @joaojunior please submit another PR to fix this.

@willingc I don't think @asvetlov had a chance to review this PR :(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@1st1 Ok, I will send.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oops. Sorry @1st and @asvetlov. I messed up on that. 😞

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@joaojunior never mind, it's handled in #9579

@asvetlov
Copy link
Copy Markdown
Contributor

Sorry, I have a pretty busy week.
Question: if we want to remove the parameter in 4.0 should we add PendingDeprecationWarning in 3.8 and DeprecationWarning in 3.9?

@1st1
Copy link
Copy Markdown
Member

1st1 commented Sep 25, 2018

I think it's OK to leave DeprecationWarning as it's just completely non-sensical to pass the loop argument. But if you feel strongly about this (I don't) please make a PR.

njsmith added a commit to njsmith/trio that referenced this pull request Sep 26, 2018
In this PR:

  python/cpython#9415

asyncio.sleep switched to requiring a running asyncio event loop. This
is all very sensible, but broke our test that checks what happens when
some accidentally yields an asyncio.Future to the Trio run loop.
Switch the test to waiting on a Future directly.
@asvetlov
Copy link
Copy Markdown
Contributor

I know many (old but still executed) codes that pass loop to sleep() and other functions explicitly.
I used to write it myself two or three years ago for example.
From my perspective, it is as non-sensical as passing bare coroutines into wait() / gather().

I don't have a strong preference but have a feeling that we need to be consistent in API deprecation.
A subjective criterion like "how many codes do we expect to break" (statistic doesn't dot exists because the codes are mostly not public) is very unobvious and not reliable.

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.

8 participants