GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Deprecate `gen.throw(typ, val, tb)` · Issue #96348 · python/cpython

Deprecate gen.throw(typ, val, tb) #96348

New issue
Copy link
New issue
Copy link
Closed
Closed
Deprecate gen.throw(typ, val, tb)#96348
Copy link
Assignees
iritkatriel
Labels
3.12only security fixesonly security fixeseasyinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)release-blockertype-featureA feature request or enhancementA feature request or enhancement

Description

@gvanrossum
gvanrossum
opened on Aug 28, 2022
Issue body actions

CC: @iritkatriel

Issue GH-89874 gets rid of exception triples where it makes sense. I don't know if it was considered, but another place where such triples are supported is the gen.throw(). It allows passing either an exception, or a (type, value, traceback) triple where the value and traceback are optional. I think it makes sense to keep allowing passing an exception type, but I don't see the use case for passing separate type and value. We could deprecate this easily by adding a warning to gen_throw() when more than one argument is present.

Thoughts?

Reacted by Yury Selivanov

Activity

Next
  1. gvanrossum
    added
    type-featureA feature request or enhancementA feature request or enhancement
    on Aug 28, 2022
  2. rhettinger commented on Aug 28, 2022

    @rhettinger
    rhettinger
    on Aug 28, 2022
    Contributor
    More actions

    This would be a nice simplification. AFAICT, the three argument form is rarely used, so deprecating that variant won't be disruptive. Also, when the signature becomes METH_O, calls to gen.throw will get faster.

  3. iritkatriel
    changed the title [-]Deprecate `gen.throw(typ, val, exc)`[/-] [+]Deprecate `gen.throw(typ, val, tb)`[/+] on Aug 28, 2022
  4. iritkatriel commented on Aug 28, 2022

    @iritkatriel
    iritkatriel
    on Aug 28, 2022
    Member
    More actions

    Yes, this would be good. The triplet is not just wasteful, it's also ambiguous when val.__traceback__ != tb.

  5. iritkatriel
    self-assigned this
    on Aug 28, 2022
  6. gvanrossum commented on Aug 28, 2022

    @gvanrossum
    gvanrossum
    on Aug 28, 2022
    MemberAuthor
    More actions

    I wonder if this could be marked as an "easy" issue for someone with moderate C skills to tackle? All you have to do (for now) is issue a deprecation warning if the arg count is larger than 1. (And update some docs.)

    Reacted by Irit Katriel and Raymond Hettinger
  7. iritkatriel
    removed their assignment
    on Aug 28, 2022
  8. iritkatriel
    added
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    easy
    3.12only security fixesonly security fixes
    release-blocker
    on Aug 28, 2022
  9. ezio-melotti
    added this to Release and Deferred blockers 🚫on Aug 28, 2022
  10. ezio-melotti
    moved this to Todo in Release and Deferred blockers 🚫on Aug 28, 2022
  11. iritkatriel commented on Aug 28, 2022

    @iritkatriel
    iritkatriel
    on Aug 28, 2022
    Member
    More actions

    Marked as easy, but also as release-blocker for 3.12 so we won't forget.

  12. ofey404 commented on Aug 29, 2022

    @ofey404
    ofey404
    on Aug 29, 2022
    Contributor
    More actions

    I wonder if this could be marked as an "easy" issue for someone with moderate C skills to tackle? All you have to do (for now) is issue a deprecation warning if the arg count is larger than 1. (And update some docs.)

    Does it locate in Objects/iterobject.c? I'm trying to become a core developer and willing to help.

    cpython/Objects/iterobject.c

    Lines 413 to 416 in af368a7

    static PyObject *
    anextawaitable_throw(anextawaitableobject *obj, PyObject *arg) {
    return anextawaitable_proxy(obj, "throw", arg);
    }

    And the (type, value, traceback) triple documentation:

    help(a.throw)
    Help on built-in function throw:
    
    throw(...) method of builtins.generator instance
        throw(typ[,val[,tb]]) -> raise exception in generator,
        return next yielded value or raise StopIteration.
    
  13. 12 remaining items

  14. ofey404 commented on Aug 31, 2022

    @ofey404
    ofey404
    on Aug 31, 2022
    Contributor
    More actions

    The problem size is not so large. I'll try to submit a version fixing them.

    With regex throw\(.*,.*,.*\), there are 51 results in 12 files.

    • 3 file is under Lib
    • 1 is in Lib/lib2to3/fixes
    • The rest are tests.
    • 51 results in 12 files.txt
  15. iritkatriel commented on Aug 31, 2022

    @iritkatriel
    iritkatriel
    on Aug 31, 2022
    Member
    More actions

    Not all of them need to be ‘fixed’ though.

    Some of the tests are testing the deprecated API and need to stay (with the deprecation warning suppressed).

    lib2to3 maps the deprecated form to the single arg form. It should not change.

    Also, I would run the tests and see what fails rather than rely on a regex search.

  16. iritkatriel commented on Aug 31, 2022

    @iritkatriel
    iritkatriel
    on Aug 31, 2022
    Member
    More actions

    Note also that just emitting a deprecation warning doesn’t cause tests to fail (we don’t run the tests with warnings-as-errors in CI).

    This is why I suggested the change in #96348 (comment), because that actually causes most (if not all) of the test failures.

  17. ofey404 commented on Aug 31, 2022

    @ofey404
    ofey404
    on Aug 31, 2022
    Contributor
    More actions

    This is why I suggested the change in #96348 (comment), because that actually causes most (if not all) of the test failures.

    You're right.

  18. kumaraditya303
    assigned
    iritkatriel
    and
    gvanrossum
    on Sep 6, 2022
  19. gvanrossum
    removed their assignment
    on Sep 14, 2022
  20. iritkatriel
    added a commit that references this issue on Sep 30, 2022

    gh-96348: Deprecate the 3-arg signature of coroutine.throw and genera…

    83a3de4
  21. ofey404 commented on Sep 30, 2022

    @ofey404
    ofey404
    on Sep 30, 2022
    Contributor
    More actions

    Should we close this since the PR is merged?

  22. kumaraditya303
    closed this as completedon Sep 30, 2022
  23. Repository owner moved this from Todo to Done in Release and Deferred blockers 🚫on Sep 30, 2022
  24. serhiy-storchaka
    added a commit that references this issue on Oct 2, 2022

    pythongh-96348: Deprecate the 3-arg signature of coroutine.throw and …

    3c84af2
  25. gvanrossum commented on Oct 11, 2022

    @gvanrossum
    gvanrossum
    on Oct 11, 2022 via email
    MemberAuthor
    More actions
    Search other C files in the same directory for DeprecationWarning.
    …
    -- --Guido (mobile)
  26. AdamWill commented on Oct 28, 2023

    @AdamWill
    AdamWill
    on Oct 28, 2023
    Contributor
    More actions

    Wasn't this deprecation rather aggressive?

    For generators at least, the single-argument form was only added in Python 3.9, at least according to the docs. It's not mentioned in the 3.8 docs, it only appears in the 3.9 docs.

    3.8 is still in support for another whole year. So if I'm trying to fix something - like twisted - to not print deprecation warnings constantly on Python 3.12, I either have to break it for a still-supported version of Python, or use some kind of rather ugly conditional to figure out what to pass it, right?

  27. AdamWill commented on Oct 28, 2023

    @AdamWill
    AdamWill
    on Oct 28, 2023
    Contributor
    More actions

    ...or is this similar to #105269 and the single-argument form was actually added earlier, but not documented?

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

Metadata

Metadata

Assignees

  • @iritkatriel
    iritkatriel

Labels

3.12only security fixesonly security fixeseasyinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)release-blockertype-featureA feature request or enhancementA feature request or enhancement

Projects

  • Release and Deferred blockers 🚫
    Status
    Done
    Show more project fields

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.