Skip to content

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

Description

@jnoortheen

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

Activity

  1. arhadthedev commented on Jun 17, 2023

    @arhadthedev
    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")))
  2. barneygale commented on Jun 17, 2023

    @barneygale
    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!

  3. jnoortheen commented on Jun 17, 2023

    @jnoortheen
    Author

    Thanks for clarifying !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions