Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
iritkatriel merged 30 commits intopython:mainfromofey404:ofey404/deprecate-get-throw
Sep 30, 2022

Conversation

ofey404
Copy link
Contributor

@ofey404ofey404 commentedAug 30, 2022
edited by bedevere-bot
Loading

Add an deprecation warning, whennargs > 1 inObjects/genobject.c:gen_throw.

  • Also change corresponding docstrings.

@bedevere-bot
Copy link

Most changes to Pythonrequire a NEWS entry.

Please add it using theblurb_it web app or theblurb command-line tool.

@ofey404
Copy link
ContributorAuthor

There is a problem: raiseDeprecationWarning will break many lib tests, since they use the (type, val, tb) exception representation.

Eg:

try:
self.gen.throw(typ,value,traceback)

Copy link
Member

@gvanrossumgvanrossum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

One nit. Too bad about the failing tests, let's brainstorm what to do about them:

  • We could just fix them, replacing.throw(A, B, C) with.throw(B).
  • We could addfilterwarnings() calls to the offending tests (I don't recall how to do that but there are probable plenty of examples).
  • We could report aSilentDeprecationWarning, then gradually fix the tests, and then later change it into aDeprecationWarning.
  • We could first fix the tests, in batches, and then land this PR.

@gvanrossum
Copy link
Member

We could report aSilentDeprecationWarning, then gradually fix the tests, and then later change it into aDeprecationWarning.

Whoops, there's no such thing. Maybe it once existed, but it doesn't now, so ignore this option. :-)

@ofey404
Copy link
ContributorAuthor

One nit. Too bad about the failing tests, let's brainstorm what to do about them:

Let's estimate the problem size, by finding with regexthrow\(.*,.*,.*\)

There are 51 results in 12 files.


  • We could just fix them, replacing .throw(A, B, C) with .throw(B).
  • We could first fix the tests, in batches, and then land this PR.

I prefer fixing them in this PR, for the fix need to be verified by raising an error. Otherwise the batch fix might miss something.

  • However, the batch plan would be clearer, in Issue and PR history.

We could add filterwarnings() calls to the offending tests (I don't recall how to do that but there are probable plenty of examples).

filterwarnings() call might be a safety valve, if I am not quite confident about how some tests work.

@gvanrossum
Copy link
Member

Okay, make sure you considerthis.

Also, some of the hits may be tests for this very feature, those should not be "fixed" but you may have to add awith self.warns() on those.

Co-authored-by: Guido van Rossum <gvanrossum@gmail.com>
@bedevere-bot
Copy link

Most changes to Pythonrequire a NEWS entry.

Please add it using theblurb_it web app or theblurb command-line tool.

@ofey404
Copy link
ContributorAuthor

ofey404 commentedSep 1, 2022
edited
Loading

I run./python -m test,and fixed clear cases, changed them to.throw(val) form.

However, there are still someDeprecationWarnings need to be handle. As@iritkatriel said incomment of 96348, some of the tests need to stay.

1. Generator's doc test

I think we should filter theDeprecationWarning here, for it's testing exactly the deprecated API.

>>> g.throw(ValueError, ValueError(1)) # value+matching type
caught ValueError (1)
>>> g.throw(ValueError, TypeError(1)) # mismatched type, rewrapped
caught ValueError (1)
>>> g.throw(ValueError, ValueError(1), None) # explicit None traceback
caught ValueError (1)
>>> g.throw(ValueError(1), "foo") # bad args
Traceback (most recent call last):
...
TypeError: instance exception may not have a separate value
>>> g.throw(ValueError, "foo", 23) # bad args

2. Libunittest.case

It happens here:

withself:
callable_obj(*args,**kwargs)

The output is like:

/../cpython/Lib/unittest/case.py:237: DeprecationWarning: the (type, val, tb) exception representationis deprecated, and may be removed in a future version of Python.  callable_obj(*args, **kwargs)

I am not sure whatcallable_obj does here, and maybe filtering this warning requires a change in standard library of python?

@iritkatriel
Copy link
Member

/../cpython/Lib/unittest/case.py:237: DeprecationWarning: the (type, val, tb) exception representationis deprecated, and may be removed in a future version of Python.  callable_obj(*args, **kwargs)

I am not sure whatcallable_obj does here, and maybe filtering this warning requires a change in standard library of python?

Look at the code in Lib/unittest/case.py. This is part of the assertRaises mechanism. The callable_obj and the args passed to it are defined by the test, so this should be dealt with in the particular test and not here in the test framework.

@iritkatriel
Copy link
Member

I am not sure whatcallable_obj does here, and maybe filtering this warning requires a change in standard library of python?

Look at the code in Lib/unittest/case.py. This is part of the assertRaises mechanism. The callable_obj and the args passed to it are defined by the test, so this should be dealt with in the particular test and not here in the test framework.

The test is this one. It's testing the types of the triplet, so we need to keep it and suppress the deprecation warning.

    def test_future_iter_throw(self):        fut = self._new_future(loop=self.loop)        fi = iter(fut)        self.assertRaises(TypeError, fi.throw,                           Exception, Exception("elephant"), 32)        self.assertRaises(TypeError, fi.throw,                          Exception("elephant"), Exception("elephant"))        self.assertRaises(TypeError, fi.throw, list)

ofey404and others added2 commitsSeptember 3, 2022 13:46
…e-96348.xzCoTP.rstCo-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
@ofey404
Copy link
ContributorAuthor

Okay, handled the remaining warnings.

Tested with those scripts:

./python -mtest -j16> test.log; cat test.log| grep"DeprecationWarning: the (type, val, tb) exception representation is deprecated"# Come out with nothing./python -Werror -m unittest -v test.test_asyncio.test_futures.PyFutureTests.test_future_iter_throw test.test_generators# OK

Besides, should I squash all commits into one, when all the reviews are done?

@gvanrossum
Copy link
Member

Don’t squash please! It makes review harder. We will squash upon merge.

Copy link
Contributor

@kumaraditya303kumaraditya303 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This is a significant change, it should be properly documented in 3.12 What's New.

…e-96348.xzCoTP.rstCo-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
@iritkatrieliritkatriel added the 🔨 test-with-buildbotsTest PR w/ buildbots; report in status section labelSep 28, 2022
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by@iritkatriel for commit8b701d6 🤖

If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again.

@bedevere-botbedevere-bot removed the 🔨 test-with-buildbotsTest PR w/ buildbots; report in status section labelSep 28, 2022
@iritkatriel
Copy link
Member

It seems that my tests exposed some problem - there are 3 versions of futures, and only one of them is emitting the deprecation warning?

@iritkatriel
Copy link
Member

Looking at the code, if futures._CFuture is fixed (made to raise the deprecation warning) then that will fix CSubFuture as well.

@iritkatriel
Copy link
Member

So I think we need one more deprecation warning from FutureIter_throw in
Modules/_asynciomodule.c.

@ofey404
Copy link
ContributorAuthor

It seems that my tests exposed some problem - there are 3 versions of futures, and only one of them is emitting the deprecation warning?

The warning is added.


But I still feel a little dizzy about it - How do you know that we should add a test in test_futures.py? Is python future implemented by coroutine object or async generator?

  • My guess: According to the doc, so test_future.py is testing the high-level interface of coroutine object, from that we know that we should add a test oniter(future).throw.

Theconcurrent.futures module provides a high-level interface for asynchronously executing callables.
concurrent.futures — Launching parallel tasks

@iritkatriel
Copy link
Member

@kumaraditya303 How does it look now? (I'm a little dizzy by now as well).

Copy link
Contributor

@kumaraditya303kumaraditya303 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

LGTM

@kumaraditya303
Copy link
Contributor

You only need to add deprecation warning in_CFuture since it is implemented in C. The pure Python versions uses regular generators so they will automatically emit warning since warning is added togenerator.throw.

def__await__(self):
ifnotself.done():
self._asyncio_future_blocking=True
yieldself# This tells Task to wait for completion.
ifnotself.done():
raiseRuntimeError("await wasn't used with future")
returnself.result()# May raise too.
__iter__=__await__# make compatible with 'yield from'.

@iritkatrieliritkatriel added 3.12only security fixes interpreter-core(Objects, Python, Grammar, and Parser dirs) labelsSep 30, 2022
@iritkatrieliritkatriel changed the titlegh-96348: Deprecate the 3-arg signature of coroutine.throw and generator.throwgh-96348: Deprecate the 3-arg signature of coroutine.throw, generator.throw and agen.athrowSep 30, 2022
@iritkatrieliritkatriel merged commit83a3de4 intopython:mainSep 30, 2022
@@ -2996,6 +2996,11 @@ generators, coroutines do not directly support iteration.
above. If the exception is not caught in the coroutine, it propagates
back to the caller.

..versionchanged::3.12

The second signature\(type\[, value\[, traceback\]\]\) is deprecated and
Copy link
Member

@merwokmerwokSep 30, 2022
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

For future PRs, not that code should generally be marked up like

      The second signature `(type[, value[, traceback]])` is deprecated and

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@merwokmerwokmerwok left review comments

@iritkatrieliritkatrieliritkatriel approved these changes

@gvanrossumgvanrossumgvanrossum left review comments

@kumaraditya303kumaraditya303kumaraditya303 approved these changes

@markshannonmarkshannonAwaiting requested review from markshannonmarkshannon is a code owner

@1st11st1Awaiting requested review from 1st11st1 is a code owner

@asvetlovasvetlovAwaiting requested review from asvetlovasvetlov is a code owner

Assignees
No one assigned
Labels
3.12only security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

6 participants
@ofey404@bedevere-bot@gvanrossum@iritkatriel@kumaraditya303@merwok

[8]ページ先頭

©2009-2025 Movatter.jp