Skip to content
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

gh-96348: Deprecate the 3-arg signature of coroutine.throw, generator.throw and agen.athrow #96428

Merged
merged 30 commits into from
Sep 30, 2022
Merged
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
b388f9a
feat: Deprecate gen.throw(typ, val, tb)
ofey404 Aug 30, 2022
713d77a
Update Objects/genobject.c
ofey404 Aug 31, 2022
fcfb65e
fix clear cases
ofey404 Sep 1, 2022
073aa62
Update Misc/NEWS.d/next/Core and Builtins/2022-08-31-18-46-13.gh-issu…
ofey404 Sep 3, 2022
1c6ed30
Filter remaining warnings.
ofey404 Sep 3, 2022
4881855
Add deprecated info in documentation.
ofey404 Sep 6, 2022
0158816
Use versionchanged instead of deprecated.
ofey404 Sep 7, 2022
8152b7c
Update Doc/reference/expressions.rst
ofey404 Sep 9, 2022
670d8f8
more docs and what's new entry
ofey404 Sep 9, 2022
0c20b35
Edit what's new.
ofey404 Sep 10, 2022
ba9a87c
Update Objects/genobject.c
ofey404 Sep 13, 2022
7f1dd7f
Update Objects/genobject.c
ofey404 Sep 13, 2022
0b16455
Update Lib/test/test_generators.py
ofey404 Sep 13, 2022
e204cc6
Update Objects/genobject.c
ofey404 Sep 13, 2022
0873dc3
Reversed agen.athrow() documentation, and what's new with method link.
ofey404 Sep 20, 2022
4a1539c
Apply suggestions from code review
ofey404 Sep 22, 2022
85b67cb
Add DeprecationWarning, doc and what's new to agen.athrow
ofey404 Sep 22, 2022
22bb65b
Update acks, and doc of anextawaitable_throw
ofey404 Sep 22, 2022
7b786e4
Add test_async_gen_3_arg_deprecation_warning.
ofey404 Sep 24, 2022
198645a
Apply formatting suggestions from code review
ofey404 Sep 25, 2022
528031c
patchcheck.py passed
ofey404 Sep 25, 2022
53c74db
Merge branch 'main' into ofey404/deprecate-get-throw
ofey404 Sep 25, 2022
93db966
Update Misc/NEWS.d/next/Core and Builtins/2022-08-31-18-46-13.gh-issu…
ofey404 Sep 25, 2022
0e56eb9
assert that deprecation warning is emitted
iritkatriel Sep 25, 2022
8738273
stage, exploring how to capture deprecation warning rather than supre…
ofey404 Sep 28, 2022
31b2e9f
Revert "stage, exploring how to capture deprecation warning rather th…
ofey404 Sep 28, 2022
8b701d6
Merge pull request #6 from iritkatriel/pr96428
ofey404 Sep 28, 2022
70e1f28
Merge branch 'main' into ofey404/deprecate-get-throw
iritkatriel Sep 28, 2022
ed2e83a
fix test
iritkatriel Sep 28, 2022
03fc6e0
Add a warning in FutureIter_throw
ofey404 Sep 29, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Revert "stage, exploring how to capture deprecation warning rather th…
…an supress them."

This reverts commit 8738273.
ofey404 committed Sep 28, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 31b2e9f762cc920c18d31e855daa721634d01360
3 changes: 2 additions & 1 deletion Lib/test/test_asyncgen.py
Original file line number Diff line number Diff line change
@@ -382,7 +382,8 @@ def test_async_gen_3_arg_deprecation_warning(self):
async def gen():
yield 123
ofey404 marked this conversation as resolved.
Show resolved Hide resolved

with self.assertWarns(DeprecationWarning):
with warnings.catch_warnings():
iritkatriel marked this conversation as resolved.
Show resolved Hide resolved
warnings.filterwarnings("ignore", category=DeprecationWarning)
gen().athrow(GeneratorExit, GeneratorExit(), None)

def test_async_gen_api_01(self):
46 changes: 29 additions & 17 deletions Lib/test/test_generators.py
Original file line number Diff line number Diff line change
@@ -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
Traceback (most recent call last):
...
DeprecationWarning: the (type, exc, tb) signature of throw() is deprecated, use the single-arg signature instead.
caught ValueError (1)
>>> g.throw(ValueError, TypeError(1)) # mismatched type, rewrapped
Traceback (most recent call last):
...
DeprecationWarning: the (type, exc, tb) signature of throw() is deprecated, use the single-arg signature instead.
caught ValueError (1)
>>> g.throw(ValueError, ValueError(1), None) # explicit None traceback
Traceback (most recent call last):
...
DeprecationWarning: the (type, exc, tb) signature of throw() is deprecated, use the single-arg signature instead.
caught ValueError (1)
>>> g.throw(ValueError(1), "foo") # bad args
Traceback (most recent call last):
...
DeprecationWarning: the (type, exc, tb) signature of throw() is deprecated, use the single-arg signature instead.
TypeError: instance exception may not have a separate value
>>> g.throw(ValueError, "foo", 23) # bad args
Traceback (most recent call last):
...
DeprecationWarning: the (type, exc, tb) signature of throw() is deprecated, use the single-arg signature instead.
TypeError: throw() third argument must be a traceback object
>>> g.throw("abc")
Traceback (most recent call last):
@@ -2159,27 +2159,39 @@ def printsolution(self, x):
... except:
... g.throw(*sys.exc_info())
>>> throw(g,ValueError) # do it with traceback included
Traceback (most recent call last):
...
DeprecationWarning: the (type, exc, tb) signature of throw() is deprecated, use the single-arg signature instead.
caught ValueError ()
>>> g.send(1)
1
>>> throw(g,TypeError) # terminate the generator
Traceback (most recent call last):
...
DeprecationWarning: the (type, exc, tb) signature of throw() is deprecated, use the single-arg signature instead.
TypeError
>>> print(g.gi_frame)
None
>>> g.send(2)
Traceback (most recent call last):
...
StopIteration
>>> g.throw(ValueError,6) # throw on closed generator
Traceback (most recent call last):
...
DeprecationWarning: the (type, exc, tb) signature of throw() is deprecated, use the single-arg signature instead.
ValueError: 6
>>> f().throw(ValueError,7) # throw on just-opened generator
Traceback (most recent call last):
...
DeprecationWarning: the (type, exc, tb) signature of throw() is deprecated, use the single-arg signature instead.
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.
Plain "raise" inside a generator should preserve the traceback (#13188).
The traceback should have 3 levels: