Feature or enhancement
Proposal:
Currently both implemenatations of relpath() are a bit inefficient. So they could use some optimisations:
- We don't need to apply
normpath() before abspath(), it already normalises it:
-start_abs = abspath(normpath(start))
-path_abs = abspath(normpath(path))
+start_abs = abspath(start)
+path_abs = abspath(path)
- We don't need to filter the segments, we just need to check if
*_rest is empty:
-start_list = [x for x in start_rest.split(sep) if x]
-path_list = [x for x in path_rest.split(sep) if x]
+start_list = start_rest.split(sep) if start_rest else []
+path_list = path_rest.split(sep) if path_rest else []
- We can use
str.join() instead of os.path.join():
-return join(*rel_list)
+return sep.join(rel_list)
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response
Linked PRs
Feature or enhancement
Proposal:
Currently both implemenatations of
relpath()are a bit inefficient. So they could use some optimisations:normpath()beforeabspath(), it already normalises it:*_restis empty:str.join()instead ofos.path.join():Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response
Linked PRs
os.path.relpath()#117608