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

Deprecation: @coroutine" decorator is deprecated since Python 3.8, use "async def" instead. #4842

Closed
thorwhalen opened this issue Jun 24, 2020 · 7 comments
Labels

Comments

@thorwhalen
Copy link

🐞 Describe the bug
Use of aiohttp issuing deprecation warnings for python 3.8 and will result in error in 3.10.
Apparently, changing do async def has no negative impact on the user.

💡 To Reproduce
Call any function that is decorated by @coroutine.
For example aiohttp/helpers.py:107

💡 Expected behavior
Get a deprecation warning:

  "@coroutine" decorator is deprecated since Python 3.8, use "async def" instead
-- Docs: https://docs.pytest.org/en/latest/warnings.html

📋 Logs/tracebacks

📋 Your version of the Python

$  python --version
Python 3.8.2
...

📋 Your version of the aiohttp/yarl/multidict distributions

$ python -m pip show aiohttp
Name: aiohttp
Version: 3.6.2
...
$ python -m pip show multidict
Name: multidict
Version: 4.7.6
...
$ python -m pip show yarl
Name: yarl
Version: 1.4.2
...
@thorwhalen thorwhalen added the bug label Jun 24, 2020
@luckydenis
Copy link

This seems to be implemented through the asyncio library. I got a message during the check. Maybe I didn’t understand to you. You can explain what you would like.

from aiohttp import web
from asyncio import coroutine

routes = web.RouteTableDef()


@coroutine
def hello(request):
    return web.Response(text="Hello, world")


app = web.Application()
app.add_routes(routes)
web.run_app(app)

stdin:

/$PATH/aiohttp/main.py:8: DeprecationWarning: "@coroutine" decorator is deprecated since Python 3.8, use "async def" instead
  def hello(request):
======== Running on http://0.0.0.0:8080 ========
(Press CTRL+C to quit)

@dstansby
Copy link

It looks like @coroutine should be replaced with async def in front of the function or method, see here: https://docs.python.org/3/reference/compound_stmts.html#async-def

@berislavlopac
Copy link

The coroutine decorator has been very practical for quickly ensuring that user provided functions (e.g. callbacks and the like) were actually coroutine functions (so they can be awaited directly). This is my simple replacement, perhaps others might find it useful:

def coroutine(fn: Callable) -> Callable:
    """ Decorator to convert a regular function to a coroutine function.

        Since asyncio.coroutine is set to be removed in 3.10, this allows
        awaiting a regular function. Not useful as a @-based decorator,
        but very helpful for inline conversions of unknown functions, and
        especially lambdas.
    """
    if iscoroutinefunction(fn):
        return fn

    @wraps(fn)
    async def _wrapper(*args, **kwargs):
        return fn(*args, **kwargs)

    return _wrapper

@sersorrel
Copy link

The problematic code here (aiohttp.helpers.noop) was actually removed in #3733, over a year ago, but it hasn't been included in a release.

It would be good to have a 3.6.x release which includes a fix for this (since the fix is very easy, replace @asyncio.coroutine with async def), especially if 4.0 is going to take a long time – https://aio-libs.discourse.group/t/aiohttp-new-release/49/12

@slmg
Copy link

slmg commented Oct 12, 2020

In the meantime, if you use pytest, disable this warning with the following config:

# pytest.ini
[pytest]
filterwarnings =
    ignore:"@coroutine" decorator is deprecated since Python 3.8, use "async def" instead:DeprecationWarning

@vEpiphyte
Copy link

Related to #4477

@asvetlov
Copy link
Member

Fixed on master and 3.7

weiji14 added a commit to weiji14/deepicedrain that referenced this issue Nov 1, 2020
Bumps [intake-geopandas](https://github.com/intake/intake_geopandas) from 0.2.3 to 0.2.3+40.ge08c8.
- [Release notes](https://github.com/intake/intake_geopandas/releases)
- [Commits](intake/intake_geopandas@0.2.3...e08c89b)

Also bumped aiohttp from 3.6.2 to 3.7.2 to silence a DeprecationWarning (see aio-libs/aiohttp#4842).
walling added a commit to walling/trading that referenced this issue Nov 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants