Skip to content

GH-44626, GH-105476: Fix ntpath.isabs() handling of part-absolute paths#113829

Merged
barneygale merged 3 commits into
python:mainfrom
barneygale:gh-44626-fix-ntpath-isabs
Jan 13, 2024
Merged

GH-44626, GH-105476: Fix ntpath.isabs() handling of part-absolute paths#113829
barneygale merged 3 commits into
python:mainfrom
barneygale:gh-44626-fix-ntpath-isabs

Conversation

@barneygale

@barneygale barneygale commented Jan 8, 2024

Copy link
Copy Markdown
Contributor

On Windows, os.path.isabs() now returns False when given a path that starts with exactly one (back)slash. This is more compatible with other functions in os.path, and with Microsoft's own documentation.

Also adjust pathlib.PureWindowsPath.is_absolute() to call ntpath.isabs(), which corrects its handling of partial UNC/device paths like //foo.


📚 Documentation preview 📚: https://cpython-previews--113829.org.readthedocs.build/

…t-absolute paths.

On Windows, `os.path.isabs()` now returns `False` when given a path that
starts with exactly one (back)slash. This is more compatible with other
functions in `os.path`, and with Microsoft's own documentation.

Also adjust `pathlib.PureWindowsPath.is_absolute()` to call
`ntpath.isabs()`, which corrects its handling of partial UNC/device paths
like `//foo`.

Co-authored-by: Jon Foster <jon@jon-foster.co.uk>
@barneygale

Copy link
Copy Markdown
Contributor Author

Thank you for the review @zooba!

@barneygale
barneygale merged commit e4ff131 into python:main Jan 13, 2024
kulikjak pushed a commit to kulikjak/cpython that referenced this pull request Jan 22, 2024
…t-absolute paths (python#113829)

On Windows, `os.path.isabs()` now returns `False` when given a path that
starts with exactly one (back)slash. This is more compatible with other
functions in `os.path`, and with Microsoft's own documentation.

Also adjust `pathlib.PureWindowsPath.is_absolute()` to call
`ntpath.isabs()`, which corrects its handling of partial UNC/device paths
like `//foo`.

Co-authored-by: Jon Foster <jon@jon-foster.co.uk>
aisk pushed a commit to aisk/cpython that referenced this pull request Feb 11, 2024
…t-absolute paths (python#113829)

On Windows, `os.path.isabs()` now returns `False` when given a path that
starts with exactly one (back)slash. This is more compatible with other
functions in `os.path`, and with Microsoft's own documentation.

Also adjust `pathlib.PureWindowsPath.is_absolute()` to call
`ntpath.isabs()`, which corrects its handling of partial UNC/device paths
like `//foo`.

Co-authored-by: Jon Foster <jon@jon-foster.co.uk>
Glyphack pushed a commit to Glyphack/cpython that referenced this pull request Sep 2, 2024
…t-absolute paths (python#113829)

On Windows, `os.path.isabs()` now returns `False` when given a path that
starts with exactly one (back)slash. This is more compatible with other
functions in `os.path`, and with Microsoft's own documentation.

Also adjust `pathlib.PureWindowsPath.is_absolute()` to call
`ntpath.isabs()`, which corrects its handling of partial UNC/device paths
like `//foo`.

Co-authored-by: Jon Foster <jon@jon-foster.co.uk>
jni pushed a commit to napari/napari that referenced this pull request Jan 2, 2025
…path.isabs change (#7482)

# References and relevant issues
Needed by: #7481

# Description
Python 3.13 changed how `os.path.isabs` works on Windows:
python/cpython#113829
Specifically, it will now return False for paths like `/foo/bar` on
Windows, while True on POSIX.
For True on Windows the path now needs to be `\\foo\bar`

We have 2 tests that use paths like `/foo/bar` and expect them to be
considered absolute.
In this PR, I add logic to test the proper paths on Windows using `\`.

You can see all tests pass on 3.13 with this fix in my fork:
https://github.com/psobolewskiPhD/napari/actions/runs/12574076907/job/35047736273

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
skshetry added a commit to treeverse/dvc that referenced this pull request Jan 10, 2025
python/cpython#113829 changed `os.path.isabs` on Windows to not consider a path starting a single backslash to be an absolute path.

We do a lot of naive `posixpath` to `ntpath` conversions, and it broke DVC in multiple places. DVC is likely broken in many other places, and these bugs are difficult to identify.

In this commit, I have tried to fix in the places where the tests failed. And mostly by trying to imitate pre-3.13 behaviour.
Some of the changes may not be correct but keeps the old behaviour in place.

Also re-enabled the CI for all Python versions supported for Windows.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic-pathlib type-bug An unexpected behavior, bug, or error

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants