summaryrefslogtreecommitdiffstats
path: root/Lib/genericpath.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2014-10-04 11:58:43 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2014-10-04 11:58:43 (GMT)
commit3deeeb0c39ee4fcc1949d127f95702edbed56943 (patch)
tree3e9963cadcb3320b1658f3187b937470c47acd71 /Lib/genericpath.py
parent385328bf761969a761d48727bfec88dccf4fe641 (diff)
downloadcpython-3deeeb0c39ee4fcc1949d127f95702edbed56943.zip
cpython-3deeeb0c39ee4fcc1949d127f95702edbed56943.tar.gz
cpython-3deeeb0c39ee4fcc1949d127f95702edbed56943.tar.bz2
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.
Diffstat (limited to 'Lib/genericpath.py')
-rw-r--r--Lib/genericpath.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/Lib/genericpath.py b/Lib/genericpath.py
index ca4a510..6714061 100644
--- a/Lib/genericpath.py
+++ b/Lib/genericpath.py
@@ -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