Add a dedicated subclass for recursion errors #63434
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
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'
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']
The text was updated successfully, but these errors were encountered:
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
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:
An cycle-detection implementation:
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.