Open filip-zyzniewski opened 1 year ago
It seems like this behavior got introduced in https://github.com/omnilib/aioitertools/commit/835bad734c297e7f4b36eda28d45be5c57290317 .
@filip-zyzniewski can you confirm if #157 matches your expected behavior?
@amyreese not exactly, please see this:
$ pwd
/Users/Filip.Zyzniewski/git/github.com/amyreese/aioitertools
$ git status
On branch zip-exception
Your branch is up to date with 'origin/zip-exception'.
Untracked files:
(use "git add <file>..." to include in what will be committed)
aioitertools_zip_exceptions.py
nothing added to commit but untracked files present (use "git add" to track)
$ git rev-parse HEAD
6285944f42395ffdca96aa388d2db1e4f545c7bb
$ cat aioitertools_zip_exceptions.py
import asyncio
import platform
import sys
import aioitertools
def gen():
for i in range(2):
yield ValueError(f"ValueError({i})")
async def agen():
for i in range(2):
yield ValueError(f"ValueError({i})")
async def main():
print("platform version", platform.version())
print("python version", sys.version)
print("aioitertools:", aioitertools)
print("aioitertools version", aioitertools.__version__)
print("zip builtin behaves as expected:")
for (i, j) in zip(range(10), gen()):
print(i, j)
print("aioitertools.zip raises an exception passed as a value:")
async for (i, j) in aioitertools.zip(range(2), agen()):
print(i, j)
asyncio.run(main())
$ python3 aioitertools_zip_exceptions.py
platform version Darwin Kernel Version 23.1.0: Mon Oct 9 21:27:24 PDT 2023; root:xnu-10002.41.9~6/RELEASE_ARM64_T6000
python version 3.11.7 (main, Dec 4 2023, 18:10:11) [Clang 15.0.0 (clang-1500.1.0.2.5)]
aioitertools: <module 'aioitertools' from '/Users/Filip.Zyzniewski/dev/git/github.com/amyreese/aioitertools/aioitertools/__init__.py'>
aioitertools version 0.11.0
zip builtin behaves as expected:
0 ValueError(0)
1 ValueError(1)
aioitertools.zip raises an exception passed as a value:
Traceback (most recent call last):
File "/Users/Filip.Zyzniewski/dev/git/github.com/amyreese/aioitertools/aioitertools_zip_exceptions.py", line 31, in <module>
asyncio.run(main())
File "/opt/homebrew/Cellar/python@3.11/3.11.7_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/runners.py", line 190, in run
return runner.run(main)
^^^^^^^^^^^^^^^^
File "/opt/homebrew/Cellar/python@3.11/3.11.7_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/runners.py", line 118, in run
return self._loop.run_until_complete(task)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Cellar/python@3.11/3.11.7_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "/Users/Filip.Zyzniewski/dev/git/github.com/amyreese/aioitertools/aioitertools_zip_exceptions.py", line 27, in main
async for (i, j) in aioitertools.zip(range(2), agen()):
File "/Users/Filip.Zyzniewski/dev/git/github.com/amyreese/aioitertools/aioitertools/builtins.py", line 441, in zip
raise v
ValueError: ValueError(0)
$
Description
What happens:
What I expected to happen: I expected the exception to percolate up the call stack and be raised at the top level.
Details