[issue27471] sre_constants.error: bad escape \d

2016-10-16 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

All behaves as purposed. But the documentation is not accurate, and even 
misleading. It should be enhanced (issue28450).

--
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27471] sre_constants.error: bad escape \d

2016-07-08 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

It is a deprection warning in 3.5.

$ python3.5 -Wd
>>> import re
>>> re.sub(re.escape(r'(\d+?)'), '(?:\d+?)', r'(\d+?)')
/usr/lib/python3.5/re.py:182: DeprecationWarning: bad escape \d
  return _compile(pattern, flags).sub(repl, string, count)
'(?:\\d+?)'

The warning was added in issue23622, and turned into exception in issue27030.

--
nosy: +serhiy.storchaka

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27471] sre_constants.error: bad escape \d

2016-07-08 Thread R. David Murray

R. David Murray added the comment:

It's just supposed to be a warning at this point, though, so this looks like a 
bug.

--
nosy: +r.david.murray

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27471] sre_constants.error: bad escape \d

2016-07-08 Thread Matthew Barnett

Matthew Barnett added the comment:

There's a move to treat invalid escape sequences as an error (see issue 27364). 
The previous behaviour was to treat them as literals.

The replacement template string contains \d, which is not a valid escape 
sequence (it's valid for the pattern, but not the template).

--
type: crash -> behavior

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27471] sre_constants.error: bad escape \d

2016-07-08 Thread Noah Petherbridge

New submission from Noah Petherbridge:

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 
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

--
components: Regular Expressions
messages: 270010
nosy: Noah Petherbridge, ezio.melotti, mrabarnett
priority: normal
severity: normal
status: open
title: sre_constants.error: bad escape \d
type: crash
versions: Python 3.6

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com