Skip to content

Commit

Permalink
stage, exploring how to capture deprecation warning rather than supre…
Browse files Browse the repository at this point in the history
…ss them.
  • Loading branch information
ofey404 committed Sep 28, 2022
1 parent 93db966 commit 8738273
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 31 deletions.
3 changes: 1 addition & 2 deletions Lib/test/test_asyncgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,7 @@ def test_async_gen_3_arg_deprecation_warning(self):
async def gen():
yield 123

with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=DeprecationWarning)
with self.assertWarns(DeprecationWarning):
gen().athrow(GeneratorExit, GeneratorExit(), None)

def test_async_gen_api_01(self):
Expand Down
46 changes: 17 additions & 29 deletions Lib/test/test_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -2113,30 +2113,30 @@ def printsolution(self, x):
>>> g.throw(ValueError("xyz")) # value only
caught ValueError (xyz)
>>> import warnings
>>> warnings.filterwarnings("ignore", category=DeprecationWarning)
# Filter DeprecationWarning: regarding the (type, val, tb) signature of throw().
# Deprecation warnings are re-enabled below.
>>> g.throw(ValueError, ValueError(1)) # value+matching type
caught ValueError (1)
Traceback (most recent call last):
...
DeprecationWarning: the (type, exc, tb) signature of throw() is deprecated, use the single-arg signature instead.
>>> g.throw(ValueError, TypeError(1)) # mismatched type, rewrapped
caught ValueError (1)
Traceback (most recent call last):
...
DeprecationWarning: the (type, exc, tb) signature of throw() is deprecated, use the single-arg signature instead.
>>> g.throw(ValueError, ValueError(1), None) # explicit None traceback
caught ValueError (1)
Traceback (most recent call last):
...
DeprecationWarning: the (type, exc, tb) signature of throw() is deprecated, use the single-arg signature instead.
>>> g.throw(ValueError(1), "foo") # bad args
Traceback (most recent call last):
...
TypeError: instance exception may not have a separate value
DeprecationWarning: the (type, exc, tb) signature of throw() is deprecated, use the single-arg signature instead.
>>> g.throw(ValueError, "foo", 23) # bad args
Traceback (most recent call last):
...
TypeError: throw() third argument must be a traceback object
DeprecationWarning: the (type, exc, tb) signature of throw() is deprecated, use the single-arg signature instead.
>>> g.throw("abc")
Traceback (most recent call last):
Expand All @@ -2159,39 +2159,27 @@ def printsolution(self, x):
... except:
... g.throw(*sys.exc_info())
>>> throw(g,ValueError) # do it with traceback included
caught ValueError ()
Traceback (most recent call last):
...
DeprecationWarning: the (type, exc, tb) signature of throw() is deprecated, use the single-arg signature instead.
>>> g.send(1)
1
>>> throw(g,TypeError) # terminate the generator
Traceback (most recent call last):
...
TypeError
>>> print(g.gi_frame)
None
>>> g.send(2)
Traceback (most recent call last):
...
StopIteration
DeprecationWarning: the (type, exc, tb) signature of throw() is deprecated, use the single-arg signature instead.
>>> g.throw(ValueError,6) # throw on closed generator
Traceback (most recent call last):
...
ValueError: 6
DeprecationWarning: the (type, exc, tb) signature of throw() is deprecated, use the single-arg signature instead.
>>> f().throw(ValueError,7) # throw on just-opened generator
Traceback (most recent call last):
...
ValueError: 7
>>> warnings.filters.pop(0)
('ignore', None, <class 'DeprecationWarning'>, None, 0)
# Re-enable DeprecationWarning: the (type, val, tb) exception representation is deprecated,
# and may be removed in a future version of Python.
DeprecationWarning: the (type, exc, tb) signature of throw() is deprecated, use the single-arg signature instead.
Plain "raise" inside a generator should preserve the traceback (#13188).
The traceback should have 3 levels:
Expand Down

0 comments on commit 8738273

Please sign in to comment.