[issue32603] Deprecation warning on strings used in re module
New submission from Cheryl Sabella <chekat2@gmail.com>: 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. ---------- assignee: docs@python components: Documentation messages: 310300 nosy: csabella, docs@python priority: normal severity: normal status: open title: Deprecation warning on strings used in re module type: enhancement versions: Python 3.7 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue32603> _______________________________________
Zachary Ware <zachary.ware@gmail.com> added the comment: 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). ---------- nosy: +zach.ware _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue32603> _______________________________________
Cheryl Sabella <chekat2@gmail.com> added the comment: 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! ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue32603> _______________________________________
Steven D'Aprano <steve+python@pearwood.info> added the comment: 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. ---------- nosy: +steven.daprano _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue32603> _______________________________________
Pablo Galindo Salgado <pablogsal@gmail.com> added the comment: +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. ---------- nosy: +pablogsal _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue32603> _______________________________________
Change by Pablo Galindo Salgado <pablogsal@gmail.com>: ---------- keywords: +patch pull_requests: +5102 stage: -> patch review _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue32603> _______________________________________
Change by Pablo Galindo Salgado <pablogsal@gmail.com>: ---------- resolution: -> fixed stage: patch review -> resolved status: open -> closed _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue32603> _______________________________________
participants (4)
-
Cheryl Sabella
-
Pablo Galindo Salgado
-
Steven D'Aprano
-
Zachary Ware