[issue34728] deprecate *loop* argument for asyncio.sleep

2018-10-02 Thread Yury Selivanov


Yury Selivanov  added the comment:

[victor]
> Why does it not make sense to pass the loop to sleep? "it makes no sense 
> anymore" something changes?

[andrew]
`loop` argument passed to sleep should be always the same as returned from 
`get_running_loop()`.

What Andrew said.

Basically, it wasn't *ever* possible to pass a loop to sleep() that would be 
different from the loop that would run it, because sleep() is a *coroutine*.

In asyncio some APIs are functions and some are coroutines.

* asyncio.gather(), for example, is a function.  You can call it from top-level 
code (and pass an event loop to it) or from a coroutine.

* asyncio.sleep(), wait(), and wait_for() are *coroutines*; they can only be 
called from other coroutines or if you wrap them into a Task; in all cases, 
*loop* is always 100% defined for them.

Passing the loop isn't even a viable micro-optimization, it's just pointless.  
This extra argument just adds to the confusion and promotes bad patterns, so we 
want to eventually remove it.

--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34728] deprecate *loop* argument for asyncio.sleep

2018-10-02 Thread Yury Selivanov


Yury Selivanov  added the comment:


New changeset 9012a0fb4c4ec1afef9efb9fdb0964554ea17983 by Yury Selivanov in 
branch 'master':
bpo-34728: Fix asyncio tests to run under "-Werror" (GH-9661)
https://github.com/python/cpython/commit/9012a0fb4c4ec1afef9efb9fdb0964554ea17983


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34728] deprecate *loop* argument for asyncio.sleep

2018-10-02 Thread Andrew Svetlov


Andrew Svetlov  added the comment:

My understanding is:

`loop` argument passed to sleep should be always the same as returned from 
`get_running_loop()`.

Passing it explicitly can be considered as microoptimization but 
`get_running_loop()` is pretty fast now, no need for such micro-opts.

On another hand passing *non-current* loop is a serious error: nothing prevents 
to do it but the code just hangs.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34728] deprecate *loop* argument for asyncio.sleep

2018-10-02 Thread STINNER Victor


STINNER Victor  added the comment:

FYI if I recall correctly, in the past, we preferred to pass explicitly the 
loop to avoid to have to get the current loop which may add an overhead. But 
the current trend is to get rid of the explicit loop parameter.

> asyncio.sleep is a coroutine; passing a *loop* argument to it makes no sense 
> anymore.

sleep() requires the current event loop:

if loop is None:
loop = events.get_running_loop()
else:
warnings.warn("The loop argument is deprecated and scheduled for "
  "removal in Python 3.10.",
  DeprecationWarning, stacklevel=2)

future = loop.create_future()
h = loop.call_later(delay,
futures._set_result_unless_cancelled,
future, result)

Why does it not make sense to pass the loop to sleep? "it makes no sense 
anymore" something changes?

I'm not against the change, I'm just trying to understand the rationale for 
other changes :-)

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34728] deprecate *loop* argument for asyncio.sleep

2018-10-02 Thread STINNER Victor


STINNER Victor  added the comment:

There is a new PR, so I change the issue resolution again.

--
resolution: fixed -> 

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34728] deprecate *loop* argument for asyncio.sleep

2018-10-02 Thread STINNER Victor


STINNER Victor  added the comment:

> Victor, you're looking at an outdated comment on this issue.

No, I read the commit:

https://github.com/python/cpython/commit/558c49bcf3a8543d64a68de836b5d855efd56696


warnings.warn("The loop argument is deprecated and scheduled for"
  "removal in Python 4.0.",
  DeprecationWarning, stacklevel=2)

> This is what's in the master branch:

https://github.com/python/cpython/blob/d4c76d960b8b286b75c933780416ace9cda682fd/Lib/asyncio/tasks.py#L598-L599

Ah, you forgot to mention this bpo in your commit:

commit fad6af2744c0b022568f7f4a8afc93fed056d4db
Author: Yury Selivanov 
Date:   Tue Sep 25 17:44:52 2018 -0400

asyncio/docs: Replace Python 4.0 -> 3.10 (GH-9579)

Anyway, the current code is fine. Thanks.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34728] deprecate *loop* argument for asyncio.sleep

2018-10-01 Thread Yury Selivanov


Change by Yury Selivanov :


--
pull_requests: +9054
stage: needs patch -> patch review

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34728] deprecate *loop* argument for asyncio.sleep

2018-10-01 Thread Yury Selivanov


Yury Selivanov  added the comment:

> On python-committers, it has been said that 3.10 will follow Python 3.9, no?

Victor, you're looking at an outdated comment on this issue.  This is what's in 
the master branch:

https://github.com/python/cpython/blob/d4c76d960b8b286b75c933780416ace9cda682fd/Lib/asyncio/tasks.py#L598-L599

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34728] deprecate *loop* argument for asyncio.sleep

2018-10-01 Thread Serhiy Storchaka


Change by Serhiy Storchaka :


--
stage: resolved -> needs patch
status: closed -> open

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34728] deprecate *loop* argument for asyncio.sleep

2018-10-01 Thread STINNER Victor


STINNER Victor  added the comment:

> We should raise a DeprecationWarning in Python 3.8 and 3.9 and remove it in 
> 4.0.

On python-committers, it has been said that 3.10 will follow Python 3.9, no?

--
nosy: +vstinner

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34728] deprecate *loop* argument for asyncio.sleep

2018-10-01 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

Tests are failed when ran with -Werror.

$ ./python -Werror -m test -vuall test_asyncgen
...
==
ERROR: test_async_gen_asyncio_01 (test.test_asyncgen.AsyncGenAsyncioTest)
--
Traceback (most recent call last):
  File "/home/serhiy/py/cpython/Lib/test/test_asyncgen.py", line 404, in 
test_async_gen_asyncio_01
res = self.loop.run_until_complete(self.to_list(gen()))
  File "/home/serhiy/py/cpython/Lib/asyncio/base_events.py", line 582, in 
run_until_complete
return future.result()
  File "/home/serhiy/py/cpython/Lib/test/test_asyncgen.py", line 391, in to_list
async for i in gen:
  File "/home/serhiy/py/cpython/Lib/test/test_asyncgen.py", line 398, in gen
await asyncio.sleep(0.01, loop=self.loop)
  File "/home/serhiy/py/cpython/Lib/asyncio/tasks.py", line 598, in sleep
warnings.warn("The loop argument is deprecated and scheduled for "
DeprecationWarning: The loop argument is deprecated and scheduled for removal 
in Python 3.10.

==
...
(the full log is too long)

$ ./python -Werror -m test -vuall test_asyncio
...
==
FAIL: test_sleep_cancel 
(test.test_asyncio.test_tasks.PyTask_PyFuture_SubclassTests)
--
Traceback (most recent call last):
  File "/home/serhiy/py/cpython/Lib/test/test_asyncio/utils.py", line 510, in 
close_loop
loop.close()
  File "/home/serhiy/py/cpython/Lib/test/test_asyncio/utils.py", line 362, in 
close
self._gen.send(0)
  File "/home/serhiy/py/cpython/Lib/test/test_asyncio/test_tasks.py", line 
1363, in gen
self.assertAlmostEqual(10.0, when)
AssertionError: 10.0 != 0 within 7 places (10.0 difference)

==
FAIL: test_run_coroutine_threadsafe_task_factory_exception 
(test.test_asyncio.test_tasks.RunCoroutineThreadsafeTests)
Test coroutine submission from a tread to an event loop
--
Traceback (most recent call last):
  File "/home/serhiy/py/cpython/Lib/test/test_asyncio/test_tasks.py", line 
3189, in test_run_coroutine_threadsafe_task_factory_exception
self.assertEqual(len(callback.call_args_list), 1)
AssertionError: 2 != 1

--
...
(the full log is too long)

--
nosy: +serhiy.storchaka

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34728] deprecate *loop* argument for asyncio.sleep

2018-09-24 Thread Carol Willing


Change by Carol Willing :


--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34728] deprecate *loop* argument for asyncio.sleep

2018-09-24 Thread Carol Willing

Carol Willing  added the comment:


New changeset 558c49bcf3a8543d64a68de836b5d855efd56696 by Carol Willing (João 
Júnior) in branch 'master':
bpo-34728: Remove deprecate *loop* argument in asyncio.sleep (GH-9415)
https://github.com/python/cpython/commit/558c49bcf3a8543d64a68de836b5d855efd56696


--
nosy: +willingc

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34728] deprecate *loop* argument for asyncio.sleep

2018-09-19 Thread Karthikeyan Singaravelan


Change by Karthikeyan Singaravelan :


--
nosy: +xtreak

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34728] deprecate *loop* argument for asyncio.sleep

2018-09-19 Thread Felipe Rodrigues


Change by Felipe Rodrigues :


--
nosy: +fbidu

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34728] deprecate *loop* argument for asyncio.sleep

2018-09-19 Thread Roundup Robot


Change by Roundup Robot :


--
keywords: +patch
pull_requests: +8835
stage: needs patch -> patch review

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34728] deprecate *loop* argument for asyncio.sleep

2018-09-18 Thread Yury Selivanov


Yury Selivanov  added the comment:

Same for asyncio.wait and asyncio.wait_for.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34728] deprecate *loop* argument for asyncio.sleep

2018-09-18 Thread Yury Selivanov


New submission from Yury Selivanov :

asyncio.sleep is a coroutine; passing a *loop* argument to it makes no sense 
anymore.

We should raise a DeprecationWarning in Python 3.8 and 3.9 and remove it in 4.0.

--
components: asyncio
keywords: easy
messages: 325684
nosy: asvetlov, yselivanov
priority: normal
severity: normal
stage: needs patch
status: open
title: deprecate *loop* argument for asyncio.sleep
type: enhancement
versions: Python 3.8

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com