Author eryksun
Recipients eryksun, lazka, paul.moore, steve.dower, tim.golden, zach.ware
Date 2017-07-26.21:47:59
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1501105680.02.0.216302914016.issue31047@psf.upfronthosting.co.za>
In-reply-to
Content
The generic abspath implementation could be moved into the genericpath module, where it will be common to both posixpath and ntpath:

    def abspath(path):
        """Return an absolute path."""
        path = os.fspath(path)
        if not isabs(path):
            if isinstance(path, bytes):
                cwd = os.getcwdb()
            else:
                cwd = os.getcwd()
            path = join(cwd, path)
        return normpath(path)

Then replace it in ntpath if nt._getfullpathname is defined, but with a fallback to the generic implementation if OSError is raised (e.g. for " "):

    try:
        from nt import _getfullpathname
    except ImportError:
        pass
    else:
        def abspath(path):
            """Return an absolute path."""
            try:
                return _getfullpathname(path)
            except OSError:
                return genericpath.abspath(path)

This _getfullpathname version also skips the redundant fspath and normpath calls.
History
Date User Action Args
2017-07-26 21:48:00eryksunsetrecipients: + eryksun, paul.moore, tim.golden, zach.ware, steve.dower, lazka
2017-07-26 21:48:00eryksunsetmessageid: <1501105680.02.0.216302914016.issue31047@psf.upfronthosting.co.za>
2017-07-26 21:47:59eryksunlinkissue31047 messages
2017-07-26 21:47:59eryksuncreate