[New-bugs-announce] [issue36403] AsyncIterator on 3.7: __aiter__ no longer honors finally blocks

Ask Solem report at bugs.python.org
Fri Mar 22 20:15:07 EDT 2019


New submission from Ask Solem <ask at celeryproject.org>:

We use finally blocks in ``__aiter__`` like this:

```
class AsyncFinallyIterator:

   def __aiter__(self):
       for i in range(10):
           try:
               yield i
           finally:
               print('FINALLY')
```

Attached is a test for both iterators and async iterators.
The tests pass on Python 3.6, but only the non-async iterator test pass under Python 3.7.

Thanks for your attention!


This worked perfectly well in Python 3.6, but stopped working in Python 3.7.

I also verified that Iterator supports the same construct (and this works in both Python 3.6 and 3.7):

```

class FinallyIterator:

    def __iter__(self):
        for i in range(10):
            try:
                yield i
            finally:
                print('FINALLY')
```

----------
files: test_iterators_and_finally_blocks.py
keywords: 3.7regression
messages: 338630
nosy: asksol
priority: normal
severity: normal
status: open
title: AsyncIterator on 3.7: __aiter__ no longer honors finally blocks
versions: Python 3.7
Added file: https://bugs.python.org/file48229/test_iterators_and_finally_blocks.py

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue36403>
_______________________________________


More information about the New-bugs-announce mailing list