Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32k
Description
In Python 3.6,invalid escape sequence were deprecated in string literals (bytes and str): issue#71551, commit110b6fe.
What's New in Python 3.6: Deprecated Python behavior:
A backslash-character pair that is not a valid escape sequence now generates a DeprecationWarning. Although this will eventually become a SyntaxError, that will not be for several Python releases. (Contributed by Emanuel Barry in bpo-27364.)
I propose now raises a SyntaxError, rather than a DeprecationWarning (which is silent in most cases).
Example:
$ python3 -W default -c 'print(list("\z"))'<string>:1: DeprecationWarning: invalid escape sequence '\z'['\\', 'z']$ python3 -W default -c 'print(list(b"\z"))'<string>:1: DeprecationWarning: invalid escape sequence '\z'[92, 122]
Note: Python REPL ate some DeprecationWarning which makes manual testing harder. It was fixed last month by commit426d72e in issuegh-96052.
Python 3.11 now emits a deprecation warning forinvalidoctal escape sequence (issuegh-81548):
Octal escapes in string and bytes literals with value larger than 0o377 now produce DeprecationWarning. In a future Python version they will be a SyntaxWarning and eventually a SyntaxError. (Contributed by Serhiy Storchaka ingh-81548.)
Example:
$ python3.11 -Wdefault -c 'print(list(b"\777"))'<string>:1: DeprecationWarning: invalid octal escape sequence '\777'[255]