Skip to content

Instantly share code, notes, and snippets.

@filip-zyzniewski
Created September 19, 2023 05:48
Show Gist options
  • Save filip-zyzniewski/1bb9c2dbde5da1dfeea5154f6e8a81f7 to your computer and use it in GitHub Desktop.
Save filip-zyzniewski/1bb9c2dbde5da1dfeea5154f6e8a81f7 to your computer and use it in GitHub Desktop.
aioitertools zip exception
$ pwd
/Users/Filip.Zyzniewski/git/github.com/omnilib/aioitertools
$
$ git status
On branch main
Your branch is up to date with 'origin/main'.
Untracked files:
(use "git add <file>..." to include in what will be committed)
aioitertools_zip_exception.py
nothing added to commit but untracked files present (use "git add" to track)
$ git rev-parse HEAD
53e15e38c4e1b5fea4876fa5f35883f11de015ff
$ cat aioitertools_zip_exception.py
import asyncio
import platform
import sys
import aioitertools
async def gen():
for i in range(10):
if i == 9:
assert False
await asyncio.sleep(1)
yield i
async def gen_pairs():
for i in range(10):
if i == 9:
assert False
await asyncio.sleep(1)
yield i, "a"
async def main():
print("platform version", platform.version())
print("python version", sys.version)
print("aioitertools:", aioitertools)
print("aioitertools version", aioitertools.__version__)
print("the exception is getting swallowed:")
async for (i, j) in aioitertools.zip(gen(), gen()):
print(i, j)
print("this attempts to unpack the exception:")
async for (i, j), (k, l) in aioitertools.zip(gen_pairs(), gen_pairs()):
print(i, j, k, l)
asyncio.run(main())
$ python3 aioitertools_zip_exception.py
platform version Darwin Kernel Version 22.6.0: Wed Jul 5 22:22:05 PDT 2023; root:xnu-8796.141.3~6/RELEASE_ARM64_T6000
python version 3.11.5 (main, Aug 24 2023, 15:09:45) [Clang 14.0.3 (clang-1403.0.22.14.1)]
aioitertools: <module 'aioitertools' from '/Users/Filip.Zyzniewski/dev/git/github.com/omnilib/aioitertools/aioitertools/__init__.py'>
aioitertools version 0.11.0
the exception is getting swallowed:
0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
this attempts to unpack the exception:
0 a 0 a
1 a 1 a
2 a 2 a
3 a 3 a
4 a 4 a
5 a 5 a
6 a 6 a
7 a 7 a
8 a 8 a
Traceback (most recent call last):
File "/Users/Filip.Zyzniewski/dev/git/github.com/omnilib/aioitertools/aioitertools_zip_exception.py", line 39, in <module>
asyncio.run(main())
File "/opt/homebrew/Cellar/[email protected]/3.11.5/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/runners.py", line 190, in run
return runner.run(main)
^^^^^^^^^^^^^^^^
File "/opt/homebrew/Cellar/[email protected]/3.11.5/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/[email protected]/3.11.5/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/omnilib/aioitertools/aioitertools_zip_exception.py", line 35, in main
async for (i, j), (k, l) in aioitertools.zip(gen_pairs(), gen_pairs()):
^^^^^^
TypeError: cannot unpack non-iterable AssertionError object
$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment