Issue #23780: Improved error message in os.path.join() with single argument.
Idea by R. David Murray.
This commit is contained in:
parent
6baa0a53b0
commit
5bfc03f430
|
@ -53,6 +53,8 @@ def join(s, *p):
|
||||||
try:
|
try:
|
||||||
colon = _get_colon(s)
|
colon = _get_colon(s)
|
||||||
path = s
|
path = s
|
||||||
|
if not p:
|
||||||
|
path[:0] + colon #23780: Ensure compatible data type even if p is null.
|
||||||
for t in p:
|
for t in p:
|
||||||
if (not path) or isabs(t):
|
if (not path) or isabs(t):
|
||||||
path = t
|
path = t
|
||||||
|
|
|
@ -81,6 +81,8 @@ def join(path, *paths):
|
||||||
seps = '\\/'
|
seps = '\\/'
|
||||||
colon = ':'
|
colon = ':'
|
||||||
try:
|
try:
|
||||||
|
if not paths:
|
||||||
|
path[:0] + sep #23780: Ensure compatible data type even if p is null.
|
||||||
result_drive, result_path = splitdrive(path)
|
result_drive, result_path = splitdrive(path)
|
||||||
for p in paths:
|
for p in paths:
|
||||||
p_drive, p_path = splitdrive(p)
|
p_drive, p_path = splitdrive(p)
|
||||||
|
|
|
@ -76,6 +76,8 @@ def join(a, *p):
|
||||||
sep = _get_sep(a)
|
sep = _get_sep(a)
|
||||||
path = a
|
path = a
|
||||||
try:
|
try:
|
||||||
|
if not p:
|
||||||
|
path[:0] + sep #23780: Ensure compatible data type even if p is null.
|
||||||
for b in p:
|
for b in p:
|
||||||
if b.startswith(sep):
|
if b.startswith(sep):
|
||||||
path = b
|
path = b
|
||||||
|
|
|
@ -448,6 +448,10 @@ class CommonTest(GenericTest):
|
||||||
self.pathmodule.join(42, 'str')
|
self.pathmodule.join(42, 'str')
|
||||||
with self.assertRaisesRegex(TypeError, errmsg % 'int'):
|
with self.assertRaisesRegex(TypeError, errmsg % 'int'):
|
||||||
self.pathmodule.join('str', 42)
|
self.pathmodule.join('str', 42)
|
||||||
|
with self.assertRaisesRegex(TypeError, errmsg % 'int'):
|
||||||
|
self.pathmodule.join(42)
|
||||||
|
with self.assertRaisesRegex(TypeError, errmsg % 'list'):
|
||||||
|
self.pathmodule.join([])
|
||||||
with self.assertRaisesRegex(TypeError, errmsg % 'bytearray'):
|
with self.assertRaisesRegex(TypeError, errmsg % 'bytearray'):
|
||||||
self.pathmodule.join(bytearray(b'foo'), bytearray(b'bar'))
|
self.pathmodule.join(bytearray(b'foo'), bytearray(b'bar'))
|
||||||
|
|
||||||
|
|
|
@ -49,6 +49,8 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #23780: Improved error message in os.path.join() with single argument.
|
||||||
|
|
||||||
- Issue #6598: Increased time precision and random number range in
|
- Issue #6598: Increased time precision and random number range in
|
||||||
email.utils.make_msgid() to strengthen the uniqueness of the message ID.
|
email.utils.make_msgid() to strengthen the uniqueness of the message ID.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue