Serhiy Storchaka added the comment: re.compile can also raise ValueError and OverflowError. Agree that may be these exceptions can be converted to re.error.
But it can also raise MemoryError, and KeyboardInterrupt. And these exceptions can't be converted to re.error. RecursionError is closer to the latter case. It depends not only on the pattern itself, but on the place where it is called. A pattern that is compiled successfully at top level can produce a RecursionError if it is compiled deeply in the recursion. >>> import re >>> def r(n): ... if not n: ... return re.compile('x') ... return r(n-1) ... >>> r(990) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<stdin>", line 4, in r File "<stdin>", line 4, in r ... File "<stdin>", line 4, in r File "<stdin>", line 3, in r File "/home/serhiy/py/cpython/Lib/re.py", line 224, in compile return _compile(pattern, flags) File "/home/serhiy/py/cpython/Lib/re.py", line 293, in _compile p = sre_compile.compile(pattern, flags) File "/home/serhiy/py/cpython/Lib/sre_compile.py", line 555, in compile p = sre_parse.parse(p, flags) File "/home/serhiy/py/cpython/Lib/sre_parse.py", line 822, in parse source = Tokenizer(str) File "/home/serhiy/py/cpython/Lib/sre_parse.py", line 225, in __init__ self.__next() RecursionError: maximum recursion depth exceeded >>> re.compile('x') re.compile('x') ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue25550> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com