Closed nineteendo closed 6 months ago
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.
I'll defer to Serhiy, who is particularly interested in such cases. cc. @serhiy-storchaka
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''
.
Bug report
Bug description:
Expected: TypeError like
npath.relpath()
.CPython versions tested on:
CPython main branch
Operating systems tested on:
Windows
Linked PRs