[Python-Dev] Re: What to do about invalid escape sequences

2019-08-10 Thread Rob Cliffe via Python-Dev
On 10/08/2019 23:30:18, Greg Ewing wrote: Rob Cliffe via Python-Dev wrote: Also, the former is simply more *informative* - it tells the reader that baz is expected to be a directory, not a file. On Windows you can usually tell that from the fact that filenames almost always have an extensi

[Python-Dev] Re: An f-string issue [Was: Re: Re: What to do about invalid escape sequences]

2019-08-10 Thread Glenn Linderman
On 8/10/2019 5:32 PM, Greg Ewing wrote: Glenn Linderman wrote: If that were true, the \n in the above example would already be a newline character, and the parsing of the format expression would not see the backslash. And if it were true, that would actually be far more useful for this situati

[Python-Dev] Re: An f-string issue [Was: Re: Re: What to do about invalid escape sequences]

2019-08-10 Thread Greg Ewing
Glenn Linderman wrote: If that were true, the \n in the above example would already be a newline character, and the parsing of the format expression would not see the backslash. And if it were true, that would actually be far more useful for this situation. But then it would fail for a differ

[Python-Dev] Re: An f-string issue [Was: Re: Re: What to do about invalid escape sequences]

2019-08-10 Thread Eric V. Smith
n 8/10/2019 7:46 PM, Glenn Linderman wrote: Because of the "invalid escape sequence" and "raw string" discussion, when looking at the documentation, I also noticed the following description for f-strings: Escape sequences are decoded like in ordinary string literals (except when a literal is

[Python-Dev] An f-string issue [Was: Re: Re: What to do about invalid escape sequences]

2019-08-10 Thread Glenn Linderman
Because of the "invalid escape sequence" and "raw string" discussion, when looking at the documentation, I also noticed the following description for f-strings: Escape sequences are decoded like in ordinary string literals (except when a literal is also marked as a raw string). After decoding,

[Python-Dev] Re: What to do about invalid escape sequences

2019-08-10 Thread Glenn Linderman
On 8/10/2019 3:36 PM, Greg Ewing wrote: Glenn Linderman wrote: I wonder how many raw strings actually use the \"  escape productively? Maybe that should be deprecated too! ?  I can't think of a good and necessary use for it, can anyone? Quite rare, I expect, but it's bound to break someone'

[Python-Dev] Re: What to do about invalid escape sequences

2019-08-10 Thread Greg Ewing
Glenn Linderman wrote: I wonder how many raw strings actually use the \" escape productively? Maybe that should be deprecated too! ? I can't think of a good and necessary use for it, can anyone? Quite rare, I expect, but it's bound to break someone's code. It might be better to introduce a

[Python-Dev] Re: What to do about invalid escape sequences

2019-08-10 Thread Greg Ewing
Rob Cliffe via Python-Dev wrote: Also, the former is simply more *informative* - it tells the reader that baz is expected to be a directory, not a file. On Windows you can usually tell that from the fact that filenames almost always have an extension, and directory names almost never do. --

[Python-Dev] Re: What to do about invalid escape sequences

2019-08-10 Thread eryk sun
On 8/10/19, Rob Cliffe via Python-Dev wrote: > On 10/08/2019 11:50:35, eryk sun wrote: >> On 8/9/19, Steven D'Aprano wrote: >>> I'm also curious why the string needs to *end* with a backslash. Both of >>> these are the same path: >>> >>> C:\foo\bar\baz\ >>> C:\foo\bar\baz > > Also, the

[Python-Dev] Re: What to do about invalid escape sequences

2019-08-10 Thread Glenn Linderman
On 8/10/2019 12:19 PM, Guido van Rossum wrote: Regular expressions. I assume that is in response to the "good use for \" escape" question? But can't you just surround them with ' instead of " ?  Or  ''' ? On Sat, Aug 10, 2019 at 12:12 Glenn Linderman > wrote:

[Python-Dev] Re: What to do about invalid escape sequences

2019-08-10 Thread Guido van Rossum
Regular expressions. On Sat, Aug 10, 2019 at 12:12 Glenn Linderman wrote: > On 8/10/2019 11:16 AM, Terry Reedy wrote: > > On 8/10/2019 4:33 AM, Paul Moore wrote: > > (Side issue) > > > This deserves its own thread. > > As a Windows developer, who has seen far too many cases where use of > slashe

[Python-Dev] Re: What to do about invalid escape sequences

2019-08-10 Thread Glenn Linderman
On 8/10/2019 11:16 AM, Terry Reedy wrote: On 8/10/2019 4:33 AM, Paul Moore wrote: (Side issue) This deserves its own thread. As a Windows developer, who has seen far too many cases where use of slashes in filenames implies a Unix-based developer not thinking sufficiently about Windows compa

[Python-Dev] Re: What to do about invalid escape sequences

2019-08-10 Thread Rob Cliffe via Python-Dev
On 10/08/2019 11:50:35, eryk sun wrote: On 8/9/19, Steven D'Aprano wrote: I'm also curious why the string needs to *end* with a backslash. Both of these are the same path: C:\foo\bar\baz\ C:\foo\bar\baz Also, the former is simply more *informative* - it tells the reader that baz i

[Python-Dev] Re: What to do about invalid escape sequences

2019-08-10 Thread Terry Reedy
On 8/10/2019 4:33 AM, Paul Moore wrote: (Side issue) This deserves its own thread. As a Windows developer, who has seen far too many cases where use of slashes in filenames implies a Unix-based developer not thinking sufficiently about Windows compatibility, or where it leads to people hard

[Python-Dev] Re: What to do about invalid escape sequences

2019-08-10 Thread Glenn Linderman
On 8/10/2019 7:03 AM, Paul Moore wrote: On Sat, 10 Aug 2019 at 12:06, Chris Angelico wrote: On Sat, Aug 10, 2019 at 6:39 PM Paul Moore wrote: There are *many* valid ways to write Windows pathnames in your code: 1. Raw strings 2. Doubling the backslashes 3. Using pathlib (possibly with slash

[Python-Dev] Re: What to do about invalid escape sequences

2019-08-10 Thread Paul Moore
On Sat, 10 Aug 2019 at 12:06, Chris Angelico wrote: > > On Sat, Aug 10, 2019 at 6:39 PM Paul Moore wrote: > > There are *many* valid ways to write Windows pathnames in your code: > > > > 1. Raw strings > > 2. Doubling the backslashes > > 3. Using pathlib (possibly with slash as a directory separa

[Python-Dev] Re: [SPAM?] Re: What to do about invalid escape sequences

2019-08-10 Thread Richard Damon
On 8/10/19 7:05 AM, Chris Angelico wrote: > On Sat, Aug 10, 2019 at 6:39 PM Paul Moore wrote: >> There are *many* valid ways to write Windows pathnames in your code: >> >> 1. Raw strings >> 2. Doubling the backslashes >> 3. Using pathlib (possibly with slash as a directory separator, where >> it's

[Python-Dev] Re: What to do about invalid escape sequences

2019-08-10 Thread eryk sun
On 8/10/19, eryk sun wrote: > > The per-logon directory is located at "\\Sessions\\0\\DosDevices\\ Session ID>". In the Windows API, it's accessible as "//?/" or "//./", > or with any mix of forward slashes or backslashes, but only the > all-backslash form is special-cased to bypass the normalizat

[Python-Dev] Re: What to do about invalid escape sequences

2019-08-10 Thread Rob Cliffe via Python-Dev
On 06/08/2019 23:41:25, Greg Ewing wrote: Rob Cliffe via Python-Dev wrote: Sorry, that won't work.  Strings are parsed at compile time, open() is executed at run-time. It could check for control characters, which are probably the result of a backslash accident. Maybe even auto-correct them

[Python-Dev] Re: What to do about invalid escape sequences

2019-08-10 Thread Chris Angelico
On Sat, Aug 10, 2019 at 6:39 PM Paul Moore wrote: > There are *many* valid ways to write Windows pathnames in your code: > > 1. Raw strings > 2. Doubling the backslashes > 3. Using pathlib (possibly with slash as a directory separator, where > it's explicitly noted as a portable option) > 4. Using

[Python-Dev] Re: What to do about invalid escape sequences

2019-08-10 Thread eryk sun
On 8/9/19, Steven D'Aprano wrote: > > I'm also curious why the string needs to *end* with a backslash. Both of > these are the same path: > > C:\foo\bar\baz\ > C:\foo\bar\baz The above two cases are equivalent. But that's not the case for the root directory. Unlike Unix, filesystem namesp

[Python-Dev] Re: What to do about invalid escape sequences

2019-08-10 Thread Paul Moore
On Sat, 10 Aug 2019 at 00:36, Steven D'Aprano wrote: > 2. To strongly discourage newbie Windows developers from hard-coding > paths using backslashes, but to use forward slashes instead. (Side issue) As a Windows developer, who has seen far too many cases where use of slashes in filenames implie

[Python-Dev] Re: What to do about invalid escape sequences

2019-08-10 Thread Steve Holden
While not a total solution, it seems like it might be worthwhile forcing flake8 or similar checks when uploading PyPI modules. That would catch the illegal escape sequences where it really matters - before they enter the ecosystem. (general) fathead:pyxll-www sholden$ cat t.py "Docstring with ill

[Python-Dev] Re: What to do about invalid escape sequences

2019-08-10 Thread Serhiy Storchaka
10.08.19 02:04, Gregory P. Smith пише: I've merged the PR reverting the behavior in 3.8 and am doing the same in the master branch. I was going to rebase it to master and go in normal backporting process if we decide that DeprecationWarning should be in master. I waited the end of the discuss