mirror of
https://github.com/python/cpython.git
synced 2025-07-09 20:35:26 +00:00
Issue #21883: os.path.join() and os.path.relpath() now raise a TypeError with
more helpful error message for unsupported or mismatched types of arguments.
This commit is contained in:
parent
385328bf76
commit
3deeeb0c39
8 changed files with 135 additions and 89 deletions
|
@ -130,3 +130,16 @@ def _splitext(p, sep, altsep, extsep):
|
|||
filenameIndex += 1
|
||||
|
||||
return p, p[:0]
|
||||
|
||||
def _check_arg_types(funcname, *args):
|
||||
hasstr = hasbytes = False
|
||||
for s in args:
|
||||
if isinstance(s, str):
|
||||
hasstr = True
|
||||
elif isinstance(s, bytes):
|
||||
hasbytes = True
|
||||
else:
|
||||
raise TypeError('%s() argument must be str or bytes, not %r' %
|
||||
(funcname, s.__class__.__name__)) from None
|
||||
if hasstr and hasbytes:
|
||||
raise TypeError("Can't mix strings and bytes in path components") from None
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue