Skip to content

bpo-36921: Deprecate @coroutine and yield from in asyncio - #13334

Closed
asvetlov wants to merge 10 commits into
python:masterfrom
asvetlov:deprecate-yield-from-in-asyncio
Closed

bpo-36921: Deprecate @coroutine and yield from in asyncio#13334
asvetlov wants to merge 10 commits into
python:masterfrom
asvetlov:deprecate-yield-from-in-asyncio

Conversation

@asvetlov

@asvetlov asvetlov commented May 15, 2019

Copy link
Copy Markdown
Contributor

In favor of async def and await

https://bugs.python.org/issue36921

@matrixise matrixise left a comment

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.

@asvetlov nice PR ;-) but maybe use coroutine and future instead of coro and fut...

Comment thread Lib/asyncio/coroutines.py
return f'<{self.__class__.__name__} {coro_repr}>'

def __iter__(self):
warnings.warn("yield from coro is deprecated, please use await coro instead",

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.

Maybe use coroutine instead of the coro because I think coro is not defined in the glossary.

yield from coroutine
await coroutine

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.

Maybe.
On the other hand, I don't like too long messages.
Usually, I rely on @1st1 judgment for texts :)

Comment thread Lib/asyncio/futures.py

__iter__ = __await__ # make compatible with 'yield from'.
def __iter__(self):
warnings.warn("yield from fut is deprecated, please use await fut instead",

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.

wording
yield from future and await future

@tirkarthi tirkarthi left a comment

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.

Some deprecation warnings with ./python.exe -Werror -m test -j4 . test_typing also has a usage of @coroutine

@asyncio.coroutine
. I used a non-ssl build so I might have missed something.

test_asyncio

======================================================================
ERROR: test_handle_repr (test.test_asyncio.test_events.HandleTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/test/test_asyncio/test_events.py", line 2140, in test_handle_repr
    cb = asyncio.coroutine(noop)
  File "/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/asyncio/coroutines.py", line 114, in coroutine
    warnings.warn("@coroutine decorator is deprecated, "
DeprecationWarning: @coroutine decorator is deprecated, please use async def function instead

======================================================================
ERROR: test_iter (test.test_asyncio.test_futures.CFutureTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/test/test_asyncio/test_futures.py", line 376, in test_iter
    test()
  File "/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/test/test_asyncio/test_futures.py", line 373, in test
    arg1, arg2 = coro()
  File "/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/test/test_asyncio/test_futures.py", line 370, in coro
    yield from fut
DeprecationWarning: yield from fut is deprecated, please use await fut instead

======================================================================
ERROR: test_uninitialized (test.test_asyncio.test_futures.CFutureTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/test/test_asyncio/test_futures.py", line 196, in test_uninitialized
    iter(fut)
DeprecationWarning: yield from fut is deprecated, please use await fut instead

======================================================================
ERROR: test_iter (test.test_asyncio.test_futures.CSubFutureTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/test/test_asyncio/test_futures.py", line 376, in test_iter
    test()
  File "/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/test/test_asyncio/test_futures.py", line 373, in test
    arg1, arg2 = coro()
  File "/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/test/test_asyncio/test_futures.py", line 370, in coro
    yield from fut
DeprecationWarning: yield from fut is deprecated, please use await fut instead

======================================================================
ERROR: test_uninitialized (test.test_asyncio.test_futures.CSubFutureTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/test/test_asyncio/test_futures.py", line 196, in test_uninitialized
    iter(fut)
DeprecationWarning: yield from fut is deprecated, please use await fut instead

======================================================================
ERROR: test_iter (test.test_asyncio.test_futures.PyFutureTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/test/test_asyncio/test_futures.py", line 376, in test_iter
    test()
  File "/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/test/test_asyncio/test_futures.py", line 373, in test
    arg1, arg2 = coro()
  File "/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/test/test_asyncio/test_futures.py", line 370, in coro
    yield from fut
  File "/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/asyncio/futures.py", line 264, in __iter__
    warnings.warn("yield from fut is deprecated, please use await fut instead",
DeprecationWarning: yield from fut is deprecated, please use await fut instead

======================================================================
ERROR: test_uninitialized (test.test_asyncio.test_futures.PyFutureTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/test/test_asyncio/test_futures.py", line 196, in test_uninitialized
    iter(fut)
  File "/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/asyncio/futures.py", line 264, in __iter__
    warnings.warn("yield from fut is deprecated, please use await fut instead",
DeprecationWarning: yield from fut is deprecated, please use await fut instead

======================================================================
ERROR: test_exception_waiter (test.test_asyncio.test_streams.StreamTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/test/test_asyncio/test_streams.py", line 592, in test_exception_waiter
    def set_err():
  File "/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/asyncio/coroutines.py", line 114, in coroutine
    warnings.warn("@coroutine decorator is deprecated, "
DeprecationWarning: @coroutine decorator is deprecated, please use async def function instead

----------------------------------------------------------------------
Ran 2071 tests in 69.820s

FAILED (errors=8, skipped=102)
@asvetlov

Copy link
Copy Markdown
Contributor Author

@tirkarthi thanks! I'll take a look

@asvetlov

Copy link
Copy Markdown
Contributor Author

Well, the change is too aggressive.
Better to deprecate @coroutine only but allow yield from fut and yield from task.
It makes the same effect but much easier

@asvetlov asvetlov closed this May 15, 2019
@asvetlov
asvetlov deleted the deprecate-yield-from-in-asyncio branch September 12, 2019 12:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment