Skip to content

Modernize aiohttpparser docstring example (remove removed asyncio.coroutine)#1076

Merged
sloria merged 1 commit into
marshmallow-code:devfrom
Sanjays2402:fix/aiohttp-docstring-asyncio-coroutine
Jul 2, 2026
Merged

Modernize aiohttpparser docstring example (remove removed asyncio.coroutine)#1076
sloria merged 1 commit into
marshmallow-code:devfrom
Sanjays2402:fix/aiohttp-docstring-asyncio-coroutine

Conversation

@Sanjays2402

Copy link
Copy Markdown
Contributor

Summary

The aiohttpparser module docstring's usage example decorates a plain generator function with @asyncio.coroutine:

import asyncio
...

@asyncio.coroutine
@use_args(hello_args)
def index(request, args):
    return web.Response(body="Hello {}".format(args["name"]).encode("utf-8"))

asyncio.coroutine was deprecated in Python 3.8 and removed in Python 3.11. webargs declares support for Python 3.10–3.14 (requires-python = ">=3.10"), and on 3.11+ there is no asyncio.coroutine, so anyone copy-pasting this example hits:

AttributeError: module 'asyncio' has no attribute 'coroutine'

The parser's own implementation already uses async def / await, and examples/aiohttp_example.py uses async def index(request, args). The docstring is just stale.

Fix

Modernize the example to async def (matching the repo's own example) and drop the now-unused import asyncio. Docstring-only change; no runtime code touched.

from aiohttp import web

from webargs import fields
from webargs.aiohttpparser import use_args


hello_args = {"name": fields.Str(required=True)}


@use_args(hello_args)
async def index(request, args):
    return web.Response(body="Hello {}".format(args["name"]).encode("utf-8"))

Verification

  • Confirmed asyncio.coroutine does not exist on Python 3.11+ (hasattr(asyncio, "coroutine") is False).
  • import webargs.aiohttpparser succeeds after the change.
  • Extracted the new docstring example and ast.parsed it — valid Python.

…outine)

The module docstring's usage example decorated a plain generator
function with @asyncio.coroutine:

    @asyncio.coroutine
    @use_args(hello_args)
    def index(request, args):
        ...

asyncio.coroutine was deprecated in Python 3.8 and REMOVED in Python
3.11, so copy-pasting this example raises AttributeError on every
Python version webargs supports (>=3.10; 3.11-3.14 have no
asyncio.coroutine). The parser's own code already uses async def /
await, and examples/aiohttp_example.py uses 'async def index'.

Update the example to modern async def to match, and drop the now-unused
'import asyncio'.
@sloria

sloria commented Jul 2, 2026

Copy link
Copy Markdown
Member

thanks!

@sloria sloria merged commit 1285adc into marshmallow-code:dev Jul 2, 2026
8 checks passed
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.

2 participants