classification
Title: Add a dedicated subclass for recursion errors
Type: enhancement Stage: resolved
Components: Interpreter Core Versions: Python 3.6, Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: yselivanov Nosy List: berker.peksag, elazar, georg.brandl, larry, levkivskyi, pitrou, python-dev, r.david.murray, rhettinger, yselivanov
Priority: normal Keywords: patch

Created on 2013-10-12 16:41 by elazar, last changed 2015-07-03 05:18 by yselivanov. This issue is now closed.

Files
File name Uploaded Description Edit
recursion_error.patch georg.brandl, 2013-10-13 16:30 review
Messages (16)
msg199595 - (view) Author: Elazar Gershuni (elazar) Date: 2013-10-12 16:41
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/
msg199607 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-10-12 17:57
This sounds like a reasonable feature request to me.
msg199608 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2013-10-12 17:59
I agree.
msg199728 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2013-10-13 16:30
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.
msg200585 - (view) Author: Elazar Gershuni (elazar) Date: 2013-10-20 13:58
Looks good to me.

Is it possible to add it to 2.7? I think it won't break any PEP8-following code (e.g. not testing for type equality/identity)
msg200700 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2013-10-21 05:44
+1
msg212808 - (view) Author: Elazar Gershuni (elazar) Date: 2014-03-06 14:51
Is it going to be committed?
msg212809 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-03-06 15:04
It's an enhancement, so it can only go in 3.5, and that will happen some time after the release of 3.4.
msg244501 - (view) Author: Elazar Gershuni (elazar) Date: 2015-05-30 21:11
Ok
msg245474 - (view) Author: Elazar Gershuni (elazar) Date: 2015-06-18 17:08
So what holds it back now?
msg245478 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2015-06-18 19:32
+1.

This, unfortunately, can't go in 3.5 (too late), but I can commit this in 3.6.
msg245479 - (view) Author: Elazar Gershuni (elazar) Date: 2015-06-18 19:54
Well that's a déjà vu.
msg245480 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2015-06-18 20:07
Larry, is there any chance this can be committed in 3.5 (the change is fully backwards compatible)?
msg246114 - (view) Author: Larry Hastings (larry) * (Python committer) Date: 2015-07-03 00:55
This is fine for 3.5.
msg246134 - (view) Author: Roundup Robot (python-dev) Date: 2015-07-03 05:12
New changeset a795cf73ce6f by Yury Selivanov in branch '3.5':
Issue #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 #19235)
https://hg.python.org/cpython/rev/749d74e5dfa7
msg246135 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2015-07-03 05:18
Thanks Larry and Georg!
History
Date User Action Args
2015-07-03 05:18:28yselivanovsetstatus: open -> closed
versions: + Python 3.5
messages: + msg246135

resolution: fixed
stage: patch review -> resolved
2015-07-03 05:12:44python-devsetnosy: + python-dev
messages: + msg246134
2015-07-03 00:55:22larrysetmessages: + msg246114
2015-06-23 19:41:47levkivskyisetnosy: + levkivskyi
2015-06-18 20:07:16yselivanovsetnosy: + larry
messages: + msg245480
2015-06-18 19:54:41elazarsetmessages: + msg245479
2015-06-18 19:32:17yselivanovsetversions: + Python 3.6, - Python 3.5
nosy: + yselivanov

messages: + msg245478

assignee: yselivanov
2015-06-18 17:08:03elazarsetmessages: + msg245474
2015-05-30 21:11:34elazarsetmessages: + msg244501
2014-09-30 23:47:22berker.peksagsetnosy: + berker.peksag

stage: patch review
2014-03-06 15:04:35r.david.murraysetnosy: + r.david.murray

messages: + msg212809
versions: + Python 3.5, - Python 3.4
2014-03-06 14:51:07elazarsetmessages: + msg212808
2013-10-21 05:44:00rhettingersetnosy: + rhettinger
messages: + msg200700
2013-10-20 13:58:31elazarsetmessages: + msg200585
2013-10-13 16:30:34georg.brandlsetfiles: + recursion_error.patch
keywords: + patch
messages: + msg199728
2013-10-12 17:59:51georg.brandlsetmessages: + msg199608
2013-10-12 17:57:35pitrousetmessages: + msg199607
components: + Interpreter Core, - Library (Lib)
2013-10-12 17:41:02georg.brandlsetnosy: + pitrou
2013-10-12 17:13:02elazarsetnosy: + georg.brandl
2013-10-12 16:41:47elazarcreate