summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2011-10-18 14:40:50 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2011-10-18 14:40:50 (GMT)
commit551ba20e8ea9a4a97cf63f28b47175e084eb63cd (patch)
treea4b28e975a3e3b7bef76a97e201d1f0631b1b3e6 /Lib/test
parent6bfecd1271b305afcbe3f3f68980f89aa44e1910 (diff)
downloadcpython-551ba20e8ea9a4a97cf63f28b47175e084eb63cd.zip
cpython-551ba20e8ea9a4a97cf63f28b47175e084eb63cd.tar.gz
cpython-551ba20e8ea9a4a97cf63f28b47175e084eb63cd.tar.bz2
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.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_generators.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/Lib/test/test_generators.py b/Lib/test/test_generators.py
index 3ec209b..5f47b3e 100644
--- a/Lib/test/test_generators.py
+++ b/Lib/test/test_generators.py
@@ -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():