Skip to content

Commit 8738273

Browse files
committed
stage, exploring how to capture deprecation warning rather than supress them.
1 parent 93db966 commit 8738273

File tree

2 files changed

+18
-31
lines changed

2 files changed

+18
-31
lines changed

Lib/test/test_asyncgen.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,7 @@ def test_async_gen_3_arg_deprecation_warning(self):
382382
async def gen():
383383
yield 123
384384

385-
with warnings.catch_warnings():
386-
warnings.filterwarnings("ignore", category=DeprecationWarning)
385+
with self.assertWarns(DeprecationWarning):
387386
gen().athrow(GeneratorExit, GeneratorExit(), None)
388387

389388
def test_async_gen_api_01(self):

Lib/test/test_generators.py

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2113,30 +2113,30 @@ def printsolution(self, x):
21132113
>>> g.throw(ValueError("xyz")) # value only
21142114
caught ValueError (xyz)
21152115
2116-
>>> import warnings
2117-
>>> warnings.filterwarnings("ignore", category=DeprecationWarning)
2118-
2119-
# Filter DeprecationWarning: regarding the (type, val, tb) signature of throw().
2120-
# Deprecation warnings are re-enabled below.
2121-
21222116
>>> g.throw(ValueError, ValueError(1)) # value+matching type
2123-
caught ValueError (1)
2117+
Traceback (most recent call last):
2118+
...
2119+
DeprecationWarning: the (type, exc, tb) signature of throw() is deprecated, use the single-arg signature instead.
21242120
21252121
>>> g.throw(ValueError, TypeError(1)) # mismatched type, rewrapped
2126-
caught ValueError (1)
2122+
Traceback (most recent call last):
2123+
...
2124+
DeprecationWarning: the (type, exc, tb) signature of throw() is deprecated, use the single-arg signature instead.
21272125
21282126
>>> g.throw(ValueError, ValueError(1), None) # explicit None traceback
2129-
caught ValueError (1)
2127+
Traceback (most recent call last):
2128+
...
2129+
DeprecationWarning: the (type, exc, tb) signature of throw() is deprecated, use the single-arg signature instead.
21302130
21312131
>>> g.throw(ValueError(1), "foo") # bad args
21322132
Traceback (most recent call last):
21332133
...
2134-
TypeError: instance exception may not have a separate value
2134+
DeprecationWarning: the (type, exc, tb) signature of throw() is deprecated, use the single-arg signature instead.
21352135
21362136
>>> g.throw(ValueError, "foo", 23) # bad args
21372137
Traceback (most recent call last):
21382138
...
2139-
TypeError: throw() third argument must be a traceback object
2139+
DeprecationWarning: the (type, exc, tb) signature of throw() is deprecated, use the single-arg signature instead.
21402140
21412141
>>> g.throw("abc")
21422142
Traceback (most recent call last):
@@ -2159,39 +2159,27 @@ def printsolution(self, x):
21592159
... except:
21602160
... g.throw(*sys.exc_info())
21612161
>>> throw(g,ValueError) # do it with traceback included
2162-
caught ValueError ()
2162+
Traceback (most recent call last):
2163+
...
2164+
DeprecationWarning: the (type, exc, tb) signature of throw() is deprecated, use the single-arg signature instead.
21632165
21642166
>>> g.send(1)
21652167
1
21662168
21672169
>>> throw(g,TypeError) # terminate the generator
21682170
Traceback (most recent call last):
21692171
...
2170-
TypeError
2171-
2172-
>>> print(g.gi_frame)
2173-
None
2174-
2175-
>>> g.send(2)
2176-
Traceback (most recent call last):
2177-
...
2178-
StopIteration
2172+
DeprecationWarning: the (type, exc, tb) signature of throw() is deprecated, use the single-arg signature instead.
21792173
21802174
>>> g.throw(ValueError,6) # throw on closed generator
21812175
Traceback (most recent call last):
21822176
...
2183-
ValueError: 6
2177+
DeprecationWarning: the (type, exc, tb) signature of throw() is deprecated, use the single-arg signature instead.
21842178
21852179
>>> f().throw(ValueError,7) # throw on just-opened generator
21862180
Traceback (most recent call last):
21872181
...
2188-
ValueError: 7
2189-
2190-
>>> warnings.filters.pop(0)
2191-
('ignore', None, <class 'DeprecationWarning'>, None, 0)
2192-
2193-
# Re-enable DeprecationWarning: the (type, val, tb) exception representation is deprecated,
2194-
# and may be removed in a future version of Python.
2182+
DeprecationWarning: the (type, exc, tb) signature of throw() is deprecated, use the single-arg signature instead.
21952183
21962184
Plain "raise" inside a generator should preserve the traceback (#13188).
21972185
The traceback should have 3 levels:

0 commit comments

Comments
 (0)