You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Raise TypeError for non-paths in posixpath.relpath() #117584
Changing the exception type is a backwards-incompatible change; some people will need to rewrite their exception handling to adapt to the new behaviour. Do the pros outweigh the cons?
This is the same thing we did with non-iterables in ntpath.commonpath(): #117335
And it matches the error thrown by ntpath.relpath(), which better communicates what's wrong.
We usually do not bother with checking arguments more than necessary, especially in the Python code (which do not crash if you use wrong types or values). If the code happens to work outside the purposed area, well, someone can use it. If it fails with a weird error -- just do not do it. But in this case the change has zero performance cost, and TypeError is more suitable for None, 0 and [] than ValueError. It should be different from the error for '' and b''.
Activity
erlend-aasland commentedon Apr 6, 2024
Changing the exception type is a backwards-incompatible change; some people will need to rewrite their exception handling to adapt to the new behaviour. Do the pros outweigh the cons?
nineteendo commentedon Apr 6, 2024
This is the same thing we did with non-iterables in
ntpath.commonpath(): #117335And it matches the error thrown by
ntpath.relpath(), which better communicates what's wrong.erlend-aasland commentedon Apr 6, 2024
I'll defer to Serhiy, who is particularly interested in such cases. cc. @serhiy-storchaka
gh-117584: Raise TypeError for non-paths in posixpath.relpath() (GH-1…
serhiy-storchaka commentedon Apr 7, 2024
We usually do not bother with checking arguments more than necessary, especially in the Python code (which do not crash if you use wrong types or values). If the code happens to work outside the purposed area, well, someone can use it. If it fails with a weird error -- just do not do it. But in this case the change has zero performance cost, and TypeError is more suitable for
None,0and[]than ValueError. It should be different from the error for''andb''.pythongh-117584: Raise TypeError for non-paths in posixpath.relpath() (…