This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Deprecation warning on strings used in re module
Type: enhancement Stage: resolved
Components: Documentation Versions: Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: cheryl.sabella, docs@python, pablogsal, steven.daprano, zach.ware
Priority: normal Keywords: patch

Created on 2018-01-19 23:20 by cheryl.sabella, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 5255 merged pablogsal, 2018-01-21 02:23
Messages (5)
msg310300 - (view) Author: Cheryl Sabella (cheryl.sabella) * (Python committer) Date: 2018-01-19 23:20
I apologize if this is a duplicate question, but I couldn't find another issue about this.  It's hard to search on 're'.

In 3.7, I get a deprecation warning when using a regular string with re escape characters:
>>> s = '123abcd'
>>> re.findall('\d', s)
<stdin>:1: DeprecationWarning: invalid escape sequence \d
['1', '2', '3']

Of course, this works:
>>> s = '123abcd'
>>> re.findall(r'\d', s)
['1', '2', '3']


I know that the documentation strongly suggests using raw strings with re, but I didn't see anywhere mentioning that it would be a requirement.  I would think this would break a lot of 're' code.
msg310301 - (view) Author: Zachary Ware (zach.ware) * (Python committer) Date: 2018-01-19 23:29
This is actually combination of a deprecation in in 3.6's string literals (not related to the re module), documented here: https://docs.python.org/dev/whatsnew/3.6.html#deprecated-python-behavior (see issue27364) and showing DeprecationWarning in the REPL by default in 3.7 (PEP 565).
msg310305 - (view) Author: Cheryl Sabella (cheryl.sabella) * (Python committer) Date: 2018-01-20 00:22
Thank you, Zach.

There was some mention of regular expressions in #27364, but I'm still wondering if the DeprecationWarning should be mentioned on the re doc page and if there should be stronger language about using raw strings.

Thanks!
msg310324 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2018-01-20 05:05
I agree with Cheryl that it would be a good idea to mention this change in the re docs, since regexes are especially likely to run into this issue.
msg310361 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2018-01-20 21:37
+1 to this. I have seen a lot of regular expressions not using raw strings that makes use of "\d" and friends. I will work on a patch to the docs if that's ok.
History
Date User Action Args
2022-04-11 14:58:56adminsetgithub: 76784
2019-01-20 19:00:37pablogsalsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2018-01-21 02:23:50pablogsalsetkeywords: + patch
stage: patch review
pull_requests: + pull_request5102
2018-01-20 21:37:09pablogsalsetnosy: + pablogsal
messages: + msg310361
2018-01-20 05:05:23steven.dapranosetnosy: + steven.daprano
messages: + msg310324
2018-01-20 00:22:24cheryl.sabellasetmessages: + msg310305
2018-01-19 23:29:30zach.waresetnosy: + zach.ware
messages: + msg310301
2018-01-19 23:20:51cheryl.sabellacreate