Author serhiy.storchaka
Recipients PedanticHacker, The Compiler, r.david.murray, serhiy.storchaka
Date 2015-03-26.15:33:52
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1427384032.74.0.576774820618.issue23780@psf.upfronthosting.co.za>
In-reply-to
Content
Error message for ntpath is improved in 3.5.

>>> import ntpath
>>> ntpath.join([1, 2, 3])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/serhiy/py/cpython/Lib/ntpath.py", line 111, in join
    genericpath._check_arg_types('join', path, *paths)
  File "/home/serhiy/py/cpython/Lib/genericpath.py", line 143, in _check_arg_types
    (funcname, s.__class__.__name__)) from None
TypeError: join() argument must be str or bytes, not 'list'

I'm not sure that the case of single argument in posixpath.join needs a fix. First, any argument checks have a cost. Second, currently os.path works with string-like objects if they implement enough string methods.

But David's proposition looks enough harmless (but this line should be added inside the try block). Do you want to add tests David? If apply it to posixpath, it should by applied to ntpath too, because currently ntpath.join doesn't raise an exceptions for empty list.

> (aside: the isinstance check in _get_sep looks like a bug report waiting to happen...it will do the wrong thing if passed a bytearray or memoryview...)

It is documented that os.path only works with strings and bytes objects. It also can work with str-like objects if lucky.
History
Date User Action Args
2015-03-26 15:33:52serhiy.storchakasetrecipients: + serhiy.storchaka, r.david.murray, The Compiler, PedanticHacker
2015-03-26 15:33:52serhiy.storchakasetmessageid: <1427384032.74.0.576774820618.issue23780@psf.upfronthosting.co.za>
2015-03-26 15:33:52serhiy.storchakalinkissue23780 messages
2015-03-26 15:33:52serhiy.storchakacreate