Skip to content

RuntimeWarning: coroutine method 'aclose' of '...' was never awaited when breaking out of async for #117536

Closed
@hroncok

Description

@hroncok

Bug report

Edit: See #117536 (comment) and #117536 (comment) for simpler reproducers --@encukou

Bug description:

The following code is extracted from jinja2 tests, as I was debugging pallets/jinja#1900 -- it uses no jinja:

async def auto_aiter(iterable):
    for item in iterable:
        yield item

async def customfilter(iterable):
    items = []
    async for item in auto_aiter(iterable):
        items.append(item)
        if len(items) == 3:
            break
    return "".join(items)

import asyncio
print(asyncio.run(customfilter("yyyNNN")))
$ python3.12 asyncrepro.py 
yyy

$ python3.13 asyncrepro.py 
yyy
sys:1: RuntimeWarning: coroutine method 'aclose' of 'auto_aiter' was never awaited
RuntimeWarning: Enable tracemalloc to get the object allocation traceback

$ python3.13 -X tracemalloc asyncrepro.py 
yyy
sys:1: RuntimeWarning: coroutine method 'aclose' of 'auto_aiter' was never awaited
Object allocated at (most recent call last):
  File ".../asyncrepro.py", lineno 10
    break

This seems to be related to #89091

I am not sure if this is a regression in Python or a bug in Jinja tests, but considering Jinja folks closed my issue, I decided to report it here instead.

CPython versions tested on:

3.13

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status

    Done

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions