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

Difference in behaviour of PureWindowsPath in 3.12.0b2 with multiple slashes #105881

Closed
jnoortheen opened this issue Jun 17, 2023 · 3 comments
Closed
Assignees
Labels
3.12 bugs and security fixes 3.13 bugs and security fixes OS-windows topic-pathlib type-bug An unexpected behavior, bug, or error

Comments

@jnoortheen
Copy link

Bug report

I was trying to add Python3.12 beta 2 to the test suit of xonsh . The tests on Windows were failing because of the difference in behaviour of PureWindowsPath.

This can be reproduced like this

in Python 3.11

>>> from pathlib import PurePosixPath, PureWindowsPath
>>> PurePosixPath("///tmp")
PurePosixPath('/tmp')
>>> PureWindowsPath(r"\\\tmp")
PureWindowsPath('/tmp')

but the same in Python 3.12.0b2 would be giving different result

In [1]: from pathlib import PurePosixPath, PureWindowsPath
In [2]: PurePosixPath("///tmp")
Out[2]: PurePosixPath('/tmp')
In [3]: PureWindowsPath(r"\\\tmp")
Out[3]: PureWindowsPath('///tmp')

I've checked the changelog and this change of behaviour wasn't mentioned in it.

Your environment

  • CPython versions tested on: 3.12.0b2
  • Operating system and architecture: Windows 64bit
@jnoortheen jnoortheen added the type-bug An unexpected behavior, bug, or error label Jun 17, 2023
@arhadthedev arhadthedev added topic-pathlib 3.12 bugs and security fixes 3.13 bugs and security fixes labels Jun 17, 2023
@arhadthedev
Copy link
Member

git bisect points to 8af8f52 (gh-102003). @barneygale

How I performed the search, for reproducibility
  • script

    git bisect start
    git bisect good v3.11.0
    git bisect bad main
    git bisect run .\gh-105881.cmd
  • gh-105881.cmd:

    @echo off
    setlocal EnableDelayedExpansion
    
    git clean -fx -e gh-105881*
    call pcbuild\clean
    call pcbuild\build
    
    for /F "usebackq delims=" %%a IN (`call python.bat gh-105881.py`) do (
        if "%%a" == "PureWindowsPath('///tmp')" exit /b 1
    )
  • gh-105881.py:

    from pathlib import PureWindowsPath
    print(repr(PureWindowsPath(r"\\\tmp")))

@barneygale
Copy link
Contributor

In Python 3.12, all Windows paths beginning // or \\ are considered to be UNC paths, and so we don't remove leading slashes. In previous versions of Python the rules were more complex. More info here: #96290 (comment)

It's mentioned in the changelog (ctrl-f for "Fix handling of partial and invalid UNC drives in ntpath.splitdrive()") but the reST formatting of the entry is messed up. Will fix!

@jnoortheen
Copy link
Author

Thanks for clarifying !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.12 bugs and security fixes 3.13 bugs and security fixes OS-windows topic-pathlib type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

4 participants