I know there’s been a pretty big focus on LaTeX over the past few replies and indeed some of the examples I provided did show that some Python users have already inadvertently created effectively broken code by doing stuff like writing \textbf
without escapes such that it will end up rendering as \ extbf
instead of \textbf
. Fair enough.
But let’s return to the example of Windows paths. There’s still at least 11.7k Python scripts (see here and here) on GitHub that contain strings beginning with C:\Windows
and, actually, a ton of those paths are in fact completely valid.
Take the string "C:\Windows\System32"
. This contains no escape characters. That exact string occurs in at least 590 Python scripts on GitHub.
The change being proposed would break all of those scripts (assuming they’re not contained in comments, which most aren’t).
C:\Windows
, having 11.7k matching Python scripts, is just but one example.
What about C:\Program
? There are 34.1k matching scripts… (see here and here). All of the examples on the first page of results do not use raw strings.
That is some serious breakage… I think any future Python release breaking all that code will end up with a bunch of people on these forums asking why their code suddenly stopped working.
The benefits should justify the breakage.
So far, the benefits proposed seem to be:
- We can introduce
\e
(or any other escape code) later on without any additional breakage.
- My counter is, why not just add a
SyntaxWarning
in Python 3.14 (or another future release) for uses of \e
and then break the code in Python 3.15? Why is it necessary to break C:\Windows
, C:\Program
, C:\Users
, C:\Recovery
, etc…?
- New users will be forced to learn that they need to escape all backslashes so that their code doesn’t silently break in the future due to the addition of new escapes.
- My counter is, does that still really outweigh all this breakage? There’s a lot of other tricky stuff with Python that new users still need to learn painfully (eg, doing stuff like
x = [1]; y = [x] * 2; y[0][0] = 2; y == [[2], [2]]
eventually teaches you about mutability).
- Also why not just permanently raise
SyntaxWarning
s without ever breaking code in future releases to steer user behaviour but ultimately allow people to write C:\Windows
if that’s what they want to do and also not break code unnecessarily.
Surely, there are more options for steering behaviour and/or paving the way for new escape codes that don’t involve breaking so much code.
The great thing about Python is that it’s really easy to iterate, it’s really easy to write quick and dirty scripts, and there’s so many quick and dirty scripts you can find online to adapt yourself. Adding new breakage makes it a little less easier for Windows users and risks making it a lot harder to find old unbroken quick and dirty scripts. It also adds a bunch of work for the Python community to go back and rewrite all those C:\Windows
and C:\Program Files
hardcodes.
And to reiterate, no, it’s not too late to go back. The code is not broken yet. And it is quite easy to stop it from being broken before it’s too late.