os.path.relpath() needlessly calls abspath() when given two paths with matching anchors
#99199
Labels
type-bug
An unexpected behavior, bug, or error
barneygale commentedNov 7, 2022
•
edited
relpath()unconditionally callsabspath()to make both its arguments absolute before comparing them. This is necessary if the supplied arguments have different anchors, but it is not necessary when the paths' anchors match. We can save a call togetcwd()/_getfinalpathname()by skipping theabspath()call in this case. This should improve performance a little.For example, neither of the following should require a call to
abspath()internally:The text was updated successfully, but these errors were encountered: