Repository navigation
ntpath.abspath() always return absolute path #119826
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on May 31, 2024 - addedtype-featureA feature request or enhancementA feature request or enhancementand removedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on May 31, 2024 cc @barneygale, @eryksun
I'm mostly concerned with fixing
abspath()on Windows, by (1) using a private_path_normpath_ex()function that supports preserving a leading "." component, and (2) fixing the fallback implementation to correctly support drive-relative paths.The case of
normpath('C:.')is a bug in the C implementation that can be fixed. The pure Python implementation ofntpath.normpath()returns the correct result, "C:".Note that no changes are required for the documented behavior and call signature of
normpath()itself.@barneygale,
pathlib.PureWindowsPathwas changed in 3.12+ to preserve an explicit leading "." in the case of relative paths that are ambiguous with drive-relative paths, such as ".\C:spam", but not generally for relative paths, such as ".\con". Would it possible and reasonable to makepathlib.PureWindowsPathalways preserve an explicit initial ".", or maybe if there's only one subsequent component?Reacted by Nice ZombiesWould it possible and reasonable to make
pathlib.PureWindowsPathalways preserve an explicit initial ".", or maybe if there's only one subsequent component?I think this is too likely to break users code if
Path('foo')andPath('./foo')no longer hash/compare equal. There may be cases where users are relying on pathlib to remove that leading./.The dropping of leading
./and trailing/is called out in the pathlib docs from 3.13: https://docs.python.org/3.13/library/pathlib.html#comparison-to-the-os-and-os-path-modulesI wish I could fix it :( but I can't see a route that won't cause unreasonable breakage. I wish we'd caught this while pathlib was still provisional.
Reacted by Nice ZombiesI split up the pull request to make it easier to review. Feel free to take a look if you have time.
- changed the title
[-]Improve accuracy of `ntpath.normpath()` & `ntpath.abspath()`[/-][+]`ntpath.abspath()` always return absolute path[/+]on Nov 13, 2024 - addedstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
on Nov 14, 2024 The issue should probably be split up in 3:
normpath('C:.'): bug for relative pathsabspath('C:\x00'): always return absolute pathabspath('./con'): support qualified referencing
The third counts as a feature, but I'm not sure about the first two.
Originally posted by @nineteendo in #119938 (comment)
Let's address the above points to decide whether this one should be closed as completed or not.
The issue has already been split up, so we should decide whether always returning an absolute path for
abspath()is a bug fix or feature.Reacted by Bénédikt Tran@zooba, can this be closed?
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error3.12only security fixesonly security fixes3.13only security fixesonly security fixes3.14bugs and security fixesbugs and security fixesand removedtype-featureA feature request or enhancementA feature request or enhancement
on Dec 2, 2024 Thanks.
Feature or enhancement
Proposal:
ntpath.abspath()doesn't always return an absolute path:Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
posixpath.abspath()for relative paths #117587Linked PRs
ntpath.abspath()always return absolute path #119938