Closed as not planned
Description
Feature or enhancement
Proposal:
We could add a special case for the current directory and return it without normalising. This speeds up posixpath.relpath()
with one argument.
def abspath(path):
"""Return an absolute path."""
path = os.fspath(path)
if isinstance(path, bytes):
- if not path.startswith(b'/'):
- path = join(os.getcwdb(), path)
+ sep = b'/'
+ curdir = b'.'
+ getcwd = os.getcwdb
else:
- if not path.startswith('/'):
- path = join(os.getcwd(), path)
+ sep = '/'
+ curdir = '.'
+ getcwd = os.getcwd
+ if not path.startswith(sep):
+ if not path or path == curdir:
+ return getcwd()
+ path = join(getcwd(), path)
return normpath(path)
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere