Message270010
I found a bug in Python 3.6.0a2 that wasn't present on previous versions of Python concerning the "\d" escape sequence as used in the following regular expression:
import re
s = "hello"
s = re.sub(re.escape(r'(\d+?)'), '(?:\d+?)', s)
(The purpose of this regular expression was to translate the literal regexp string "(\d+?)" to be a non-capturing literal regexp string, to eventually be used as a re pattern).
When running this code in 3.6.0a2 I receive the following stack traces:
- - - - - - - - - -
Traceback (most recent call last):
File "/home/kirsle/.pyenv/versions/3.6.0a2/lib/python3.6/sre_parse.py", line 877, in parse_template
this = chr(ESCAPES[this][1])
KeyError: '\\d'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "test.py", line 4, in <module>
s = re.sub(re.escape(r'(\d+?)'), '(?:\d+?)', s)
File "/home/kirsle/.pyenv/versions/3.6.0a2/lib/python3.6/re.py", line 181, in sub
return _compile(pattern, flags).sub(repl, string, count)
File "/home/kirsle/.pyenv/versions/3.6.0a2/lib/python3.6/re.py", line 324, in _subx
template = _compile_repl(template, pattern)
File "/home/kirsle/.pyenv/versions/3.6.0a2/lib/python3.6/re.py", line 311, in _compile_repl
p = sre_parse.parse_template(repl, pattern)
File "/home/kirsle/.pyenv/versions/3.6.0a2/lib/python3.6/sre_parse.py", line 880, in parse_template
raise s.error('bad escape %s' % this, len(this))
sre_constants.error: bad escape \d at position 3
- - - - - - - - - -
However, the script runs without crashing on Python 3.5.1 and 2.7.11
% python --version
Python 3.6.0a2 |
|
Date |
User |
Action |
Args |
2016-07-08 21:57:07 | Noah Petherbridge | set | recipients:
+ Noah Petherbridge, ezio.melotti, mrabarnett |
2016-07-08 21:57:07 | Noah Petherbridge | set | messageid: <1468015027.73.0.234433787808.issue27471@psf.upfronthosting.co.za> |
2016-07-08 21:57:07 | Noah Petherbridge | link | issue27471 messages |
2016-07-08 21:57:07 | Noah Petherbridge | create | |
|