-
-
Notifications
You must be signed in to change notification settings - Fork 448
coverage seems to cause coroutines to skip over exeption handlers on 3.12 #1635
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Labels
bug
Something isn't working
Comments
eliminating asyncio: import types
@types.coroutine
def _async_yield(v):
return (yield v)
async def inner():
try:
await _async_yield(None)
except Exception:
print("good")
return "good2"
async def main():
return await inner()
def run(coro):
coro.send(None)
try:
coro.throw(Exception)
except StopIteration as e:
print(e.value)
run(main())
|
same with a plain generator: def inner():
try:
yield None
except Exception:
print("good")
return "good2"
def main():
return (yield from inner())
def run(coro):
coro.send(None)
try:
coro.throw(Exception)
except StopIteration as e:
print(e.value)
run(main())
|
I'm also able to reproduce this on Ubuntu w/ Python 3.12.0-beta1: (venv) $ python --version
Python 3.12.0b1
(venv) $ python -m pip freeze
coverage==7.2.7
(venv) $ coverage run -m demo
Traceback (most recent call last):
File "/tmp/demo.py", line 19, in <module>
run(main())
File "/tmp/demo.py", line 14, in run
coro.throw(Exception)
File "/tmp/demo.py", line 9, in main
return (yield from inner())
^^^^^^^^^^^^^^^^^^
Exception
(venv) $ python -m demo
good
good2 |
same issue using a manually written Inner generator: class Inner:
def send(self, v):
return None
def __iter__(self):
return self
def __next__(self):
return self.send(None)
def throw(self, *exc_info):
raise StopIteration("good")
def main():
return (yield from Inner())
def run(coro):
coro.send(None)
try:
coro.throw(Exception)
except StopIteration as e:
print(e.value)
run(main()) |
eliminating coverage: ./.nox/test-3-12/bin/python -m trace --count -C . demo.py
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "/usr/lib/python3.12/trace.py", line 741, in <module>
main()
File "/usr/lib/python3.12/trace.py", line 729, in main
t.runctx(code, globs, globs)
File "/usr/lib/python3.12/trace.py", line 451, in runctx
exec(cmd, globals, locals)
File "demo.py", line 26, in <module>
run(main())
File "demo.py", line 21, in run
coro.throw(Exception)
File "demo.py", line 16, in main
return (yield from Inner())
^^^^^^^^^^^^^^^^^^
Exception |
This turned out to be a CPython issue, so I think this can be safely closed. |
Closed, there's a CPython fix proposed already! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
urllib3/urllib3#3049 (comment)
Describe the bug
when running on 3.12b1 and coverage 7.2.7 (with C extension) coverage seems to cause coroutines to skip over exeption handlers
To Reproduce
How can we reproduce the problem? Please be specific. Don't link to a failing CI job. Answer the questions below:
coverage debug sys
is helpful. 7.2.7pip freeze
is helpful.input:
Expected behavior
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: