Eryk Sun added the comment:
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.
----------
nosy: +eryksun
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue31047>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com