diff -r 58bd6a58365d Doc/library/packaging.util.rst --- a/Doc/library/packaging.util.rst Wed Feb 08 04:09:37 2012 +0100 +++ b/Doc/library/packaging.util.rst Wed Feb 08 13:49:22 2012 +0200 @@ -64,6 +64,8 @@ in Unix style, and have to be converted to the local convention before we can actually use them in the filesystem. Raises :exc:`ValueError` on non-Unix-ish systems if *pathname* either starts or ends with a slash. + Also Raises :exc:`TypeError` if 'pathname' is not a string or is not + ``None``. .. function:: change_root(new_root, pathname) diff -r 58bd6a58365d Lib/packaging/tests/test_util.py --- a/Lib/packaging/tests/test_util.py Wed Feb 08 04:09:37 2012 +0100 +++ b/Lib/packaging/tests/test_util.py Wed Feb 08 13:49:22 2012 +0200 @@ -199,6 +199,11 @@ self.assertEqual(convert_path('.'), os.curdir) + # wrong types + wrong_types = [False, 0, 0.0, 0j, {}, [], set()] + for wrong_type in wrong_types: + self.assertRaises(TypeError, convert_path, wrong_type) + def test_change_root(self): # linux/mac os.name = 'posix' diff -r 58bd6a58365d Lib/packaging/util.py --- a/Lib/packaging/util.py Wed Feb 08 04:09:37 2012 +0100 +++ b/Lib/packaging/util.py Wed Feb 08 13:49:22 2012 +0200 @@ -104,6 +104,8 @@ ValueError on non-Unix-ish systems if 'pathname' either starts or ends with a slash. """ + if not isinstance(pathname, (str, type(None))): + raise TypeError("path name should be a string") if os.sep == '/': return pathname if not pathname: