Skip to content

gh-85681: Make ntpath.abspath() platform independent - #155395

Open
serhiy-storchaka wants to merge 1 commit into
python:mainfrom
serhiy-storchaka:gh-85681-abspath-fallback-strip
Open

gh-85681: Make ntpath.abspath() platform independent#155395
serhiy-storchaka wants to merge 1 commit into
python:mainfrom
serhiy-storchaka:gh-85681-abspath-fallback-strip

Conversation

@serhiy-storchaka

Copy link
Copy Markdown
Member

ntpath.relpath() returned different results on Windows and on other platforms:

>>> ntpath.relpath('foo ', 'foo') # on Windows
'.'
>>> ntpath.relpath('foo ', 'foo') # on other platforms
'..\\foo '

relpath() is based on abspath(), which is implemented with GetFullPathNameW() on Windows. It strips trailing dots and spaces from the last component of the path, and a single trailing dot from other components, unless it is preceded by a dot. The pure Python abspath(), used on other platforms, now does the same.

normpath() is not changed: it does not strip them on Windows either.

The rules are not documented, they were determined by testing nt._getfullpathname() on Windows 11. The added tests are run on all platforms, so they check both implementations.

On Windows the path normalization strips trailing dots and spaces from the
last component of the path, and a single trailing dot from other components.
abspath() on other platforms now does the same, so relpath() and other
functions based on it no longer depend on the platform.
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@serhiy-storchaka