mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
Issue #13188: When called without an explicit traceback argument,
generator.throw() now gets the traceback from the passed exception's `__traceback__` attribute. Patch by Petri Lehtinen.
This commit is contained in:
parent
6bfecd1271
commit
551ba20e8e
3 changed files with 35 additions and 0 deletions
|
@ -1673,6 +1673,32 @@ Traceback (most recent call last):
|
|||
...
|
||||
ValueError: 7
|
||||
|
||||
Plain "raise" inside a generator should preserve the traceback (#13188).
|
||||
The traceback should have 3 levels:
|
||||
- g.throw()
|
||||
- f()
|
||||
- 1/0
|
||||
|
||||
>>> def f():
|
||||
... try:
|
||||
... yield
|
||||
... except:
|
||||
... raise
|
||||
>>> g = f()
|
||||
>>> try:
|
||||
... 1/0
|
||||
... except ZeroDivisionError as v:
|
||||
... try:
|
||||
... g.throw(v)
|
||||
... except Exception as w:
|
||||
... tb = w.__traceback__
|
||||
>>> levels = 0
|
||||
>>> while tb:
|
||||
... levels += 1
|
||||
... tb = tb.tb_next
|
||||
>>> levels
|
||||
3
|
||||
|
||||
Now let's try closing a generator:
|
||||
|
||||
>>> def f():
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue