Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid escape sequences raise SyntaxWarning #119458

Closed
Okarin99 opened this issue May 23, 2024 · 3 comments
Closed

Invalid escape sequences raise SyntaxWarning #119458

Okarin99 opened this issue May 23, 2024 · 3 comments
Assignees

Comments

@Okarin99
Copy link

Okarin99 commented May 23, 2024

PEP 701 introduced with python version 3.12.3 claims to be backwards compatible.
But in python version 3.12.2 the string "\.00" gives \\.00 and since python version 3.12.3 I get the follwing error:
<stdin>:1: SyntaxWarning: invalid escape sequence '\.'
'\\.00'

@AlexWaygood AlexWaygood transferred this issue from python/peps May 23, 2024
@pablogsal
Copy link
Member

That has nothing to be with PEP 701. PEP 701 is about f-strings, not about strings in general. That change was introduced here:

3483299a24e4

@pablogsal pablogsal closed this as not planned Won't fix, can't repro, duplicate, stale May 23, 2024
@terryjreedy
Copy link
Member

The referenced commit is about octal sequences above 0o377. The warning results from changing the invalid escape sequence warning from DeprecationWarning (usually invisible) to SyntaxWarning (usually visible, but not currently in IDLE and other possible circumstances) in 3.12 in issue #98401, PR #99011. The same warning occurs with '\.a' and '\.'.

The change was in 3.12.0 and noted in What' New 3.12:

A backslash-character pair that is not a valid escape sequence now generates a SyntaxWarning, instead of DeprecationWarning.

If you want a single backslash in the string, either double it or precede the string with 'r': '\\.00' == r'\.00' is True.

@terryjreedy terryjreedy changed the title PEP 701 is not backwards compatible Invalid escape sequences raise SyntaxWarning May 23, 2024
@Okarin99
Copy link
Author

Okarin99 commented May 23, 2024

Ahh ok that explains everything. I got this Error because Mathematica’s ExternalEvaluate uses an invalid escape sequence and I knew that in march all was working fine. I regularly update my system so I thought I was using python version 3.12.2 in march. But it turns out that Archlinux doesn’t update their python package that often, therefore I was using version 3.11.8 instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants