← 输入框|github.com|刷新
Skip to content

os.path.abspath regression #464

Open

Description

@htniemann

On windows, a relative path may have a drive specifier (there is a current working directory per drive), see python/cpython#100809 for background information from a related problem

program is:

import os.path
print (os.path.abspath('D:..'))

result is, for CPython 2.7, Jython 2.7.0, 2.7.4 and 2.7.5beta1:

D:\Tools\Work_\030_projects\TEMP>c:\devtools\Python\27-32\python.exe xy.py
D:\Tools\Work_\030_projects

D:\Tools\Work_\030_projects\TEMP>c:\devtools\Jython\2.7.0\bin\jython.exe xy.py
D:\Tools\Work_\030_projects

D:\Tools\Work_\030_projects\TEMP>c:\devtools\Jython\2.7.5b1\bin\jython.exe xy.py
D:\Tools\Work_\030_projects\TEMP\D:..

D:\Tools\Work_\030_projects\TEMP>c:\devtools\Jython\2.7.4\bin\jython.exe xy.py
D:\Tools\Work_\030_projects\TEMP\D:..

So 2.7.0 did it correctly, 2.7.4 and 2.7.5beta don't handle this case well.

Activity

  1. jeff5 commented on Oct 27, 2026

    @jeff5
    Member

    Sounds like we broke something there in how paths are being joined.

    Although the link is interesting, I don't think the problem stems from per-drive defaults, but is simpler. I recall struggling with (and giving up on) making os.chdir work properly in that way on Windows. This is interesting on where per-drive CWDs live according to your experience at the DOS prompt: https://stackoverflow.com/questions/53078528/how-to-get-current-working-directory-of-another-drive-in-batch

  2. jeff5 commented on Oct 27, 2026

    @jeff5
    Member

    The root of this is that Jython does not provide nt._getfullpathname. Therefore when we import ntpath we take the "not running on Windows" definition of abspath. I think CPython 2.7 would behave the same way on Unix, but with a bit of effort one can explore the effect on Windows.

    Jython-2>python -S
    Python 2.7.18 (v2.7.18:8d21aa21f2, Apr 20 2020, 13:25:05) [MSC v.1500 64 bit (AMD64)] on win32
    >>> import nt
    >>> del nt._getfullpathname
    >>> import os.path
    >>> os.path.abspath('d:..')
    'd:..'
    

    In the absence of nt._getfullpathname, Python relies on ntpath.join(os.getcwd(), path), which cannot determine the CWD belonging to a drive and behaves like so:

    >>> os.path.join('c:\\a\\b\\c', 'd:..')
    'd:..'
    >>> os.path.join('d:\\x\\y', 'd:..')
    'd:\\x\\y\\..'
    

    in the first case treating d:... as absolute winner, and ignoring the CWD-per-drive issue, but in the second case spotting that the drive letters match.

    The version of ntpath we are using has older code than this that doesn't special case having the same drive. Changed in: python/cpython@31f5121

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions