Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

pathlib.Path.absolute() mishandles drive-relative Windows paths #100809

Closed
Labels
3.10only security fixes3.11only security fixes3.12only security fixestopic-pathlibtype-bugAn unexpected behavior, bug, or error
@barneygale

Description

@barneygale

Windows has one current directoryper drive, and supports drive-relative paths like 'X:' and 'X:foo.txt'. This makes a conversion from relative to absolute paths more complicated than simply prepending a (single) current directory.

It's correctly handled inntpath.abspath() by calling NT'sGetFullPathNameW() function. But in pathlib we simply prependos.getcwd(), leading to incorrect results:

>>>importos,nt,pathlib>>>os.chdir('Z:/build')>>>os.chdir('C:/')>>>os.path.abspath('Z:')'Z:\\build'>>>nt._getfullpathname('Z:')'Z:\\build'>>>pathlib.Path('Z:').absolute()WindowsPath('Z:')

This bug is present in all versions of CPython pathlib. We can't fix it by callingabspath() because it will also normalize the path, eliding '..' parts.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.10only security fixes3.11only security fixes3.12only security fixestopic-pathlibtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp