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

Add a dedicated subclass for recursion errors #63434

Closed
elazarg mannequin opened this issue Oct 12, 2013 · 16 comments
Closed

Add a dedicated subclass for recursion errors #63434

elazarg mannequin opened this issue Oct 12, 2013 · 16 comments
Assignees
Labels
interpreter-core Interpreter core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement

Comments

@elazarg
Copy link
Mannequin

elazarg mannequin commented Oct 12, 2013

BPO 19235
Nosy @birkenfeld, @rhettinger, @pitrou, @larryhastings, @bitdancer, @berkerpeksag, @1st1, @elazarg, @ilevkivskyi
Files
  • recursion_error.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/1st1'
    closed_at = <Date 2015-07-03.05:18:28.884>
    created_at = <Date 2013-10-12.16:41:47.874>
    labels = ['interpreter-core', 'type-feature']
    title = 'Add a dedicated subclass for recursion errors'
    updated_at = <Date 2015-07-03.05:18:28.882>
    user = 'https://github.com/elazarg'

    bugs.python.org fields:

    activity = <Date 2015-07-03.05:18:28.882>
    actor = 'yselivanov'
    assignee = 'yselivanov'
    closed = True
    closed_date = <Date 2015-07-03.05:18:28.884>
    closer = 'yselivanov'
    components = ['Interpreter Core']
    creation = <Date 2013-10-12.16:41:47.874>
    creator = 'elazar'
    dependencies = []
    files = ['32091']
    hgrepos = []
    issue_num = 19235
    keywords = ['patch']
    message_count = 16.0
    messages = ['199595', '199607', '199608', '199728', '200585', '200700', '212808', '212809', '244501', '245474', '245478', '245479', '245480', '246114', '246134', '246135']
    nosy_count = 10.0
    nosy_names = ['georg.brandl', 'rhettinger', 'pitrou', 'larry', 'r.david.murray', 'python-dev', 'berker.peksag', 'yselivanov', 'elazar', 'levkivskyi']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue19235'
    versions = ['Python 3.5', 'Python 3.6']

    @elazarg
    Copy link
    Mannequin Author

    elazarg mannequin commented Oct 12, 2013

    There's no dedicated StackOverflowErrorException, So there is no way to accurately distinguish a recursion overflow from a general RuntimeError.

    One cannot use the exception message, since the docs explicitly says that "Exception messages are not part of the Python API", and checking for

    len(traceback.extract_tb(trace)) >= sys.getrecursionlimit()-1
    

    is ugly, and (AFAIK) not guaranteed to be correct.

    Use case: I've found this while trying to create a cycle detector that will compress the traceback of such errors.

    See discussion in python-ideas:
    https://mail.python.org/pipermail/python-ideas/2013-September/023190.html

    An cycle-detection implementation:
    http://code.activestate.com/recipes/578660-concise-output-for-maximum-recursion-depth-exceede/

    @elazarg elazarg mannequin added stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Oct 12, 2013
    @pitrou
    Copy link
    Member

    pitrou commented Oct 12, 2013

    This sounds like a reasonable feature request to me.

    @pitrou pitrou added interpreter-core Interpreter core (Objects, Python, Grammar, and Parser dirs) and removed stdlib Python modules in the Lib dir labels Oct 12, 2013
    @birkenfeld
    Copy link
    Member

    birkenfeld commented Oct 12, 2013

    I agree.

    @birkenfeld
    Copy link
    Member

    birkenfeld commented Oct 13, 2013

    Attached is a patch, please review. Introduces a RecursionError that subclasses RuntimeError for compatibility.

    Note: I also tested this with RecursionError not subclassing RuntimeError, to make sure that except clauses in the test suite are sufficiently narrowed to RecursionError.

    @elazarg
    Copy link
    Mannequin Author

    elazarg mannequin commented Oct 20, 2013

    Looks good to me.

    Is it possible to add it to 2.7? I think it won't break any PEP-8-following code (e.g. not testing for type equality/identity)

    @rhettinger
    Copy link
    Contributor

    rhettinger commented Oct 21, 2013

    +1

    @elazarg
    Copy link
    Mannequin Author

    elazarg mannequin commented Mar 6, 2014

    Is it going to be committed?

    @bitdancer
    Copy link
    Member

    bitdancer commented Mar 6, 2014

    It's an enhancement, so it can only go in 3.5, and that will happen some time after the release of 3.4.

    @elazarg
    Copy link
    Mannequin Author

    elazarg mannequin commented May 30, 2015

    Ok

    @elazarg
    Copy link
    Mannequin Author

    elazarg mannequin commented Jun 18, 2015

    So what holds it back now?

    @1st1
    Copy link
    Member

    1st1 commented Jun 18, 2015

    +1.

    This, unfortunately, can't go in 3.5 (too late), but I can commit this in 3.6.

    @1st1 1st1 self-assigned this Jun 18, 2015
    @elazarg
    Copy link
    Mannequin Author

    elazarg mannequin commented Jun 18, 2015

    Well that's a déjà vu.

    @1st1
    Copy link
    Member

    1st1 commented Jun 18, 2015

    Larry, is there any chance this can be committed in 3.5 (the change is fully backwards compatible)?

    @larryhastings
    Copy link
    Contributor

    larryhastings commented Jul 3, 2015

    This is fine for 3.5.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jul 3, 2015

    New changeset a795cf73ce6f by Yury Selivanov in branch '3.5':
    Issue bpo-19235: Add new RecursionError exception. Patch by Georg Brandl.
    https://hg.python.org/cpython/rev/a795cf73ce6f

    New changeset 749d74e5dfa7 by Yury Selivanov in branch 'default':
    Merge 3.5 (Issue bpo-19235)
    https://hg.python.org/cpython/rev/749d74e5dfa7

    @1st1
    Copy link
    Member

    1st1 commented Jul 3, 2015

    Thanks Larry and Georg!

    @1st1 1st1 closed this as completed Jul 3, 2015
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    interpreter-core Interpreter core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    6 participants