diff -r b2bd62d1644f Lib/test/test_cmd_line.py --- a/Lib/test/test_cmd_line.py Fri Nov 02 22:07:26 2012 +0200 +++ b/Lib/test/test_cmd_line.py Sat Nov 03 13:01:20 2012 +0200 @@ -216,6 +216,23 @@ self.assertIn(path1.encode('ascii'), out) self.assertIn(path2.encode('ascii'), out) + def test_empty_PYTHONPATH_issue16309(self): + """On Posix, it is documented that setting PATH to the + empty string is equivalent to not setting PATH at all, + which is an exception to the rule that in a string like + "/bin::/usr/bin" the empty string in the middle gets + interpreted as '.'""" + code = """if 1: + import sys + path = ":".join(sys.path) + path = path.encode("ascii", "backslashreplace") + sys.stdout.buffer.write(path)""" + rc1, out1, err1 = assert_python_ok('-c', code, PYTHONPATH="") + rc2, out2, err2 = assert_python_ok('-c', code) + # regarding to Posix specification, outputs should be equal + # for empty and unset PYTHONPATH + self.assertEquals(out1, out2) + def test_displayhook_unencodable(self): for encoding in ('ascii', 'latin-1', 'utf-8'): env = os.environ.copy() diff -r b2bd62d1644f Modules/getpath.c --- a/Modules/getpath.c Fri Nov 02 22:07:26 2012 +0200 +++ b/Modules/getpath.c Sat Nov 03 13:01:20 2012 +0200 @@ -699,13 +699,11 @@ */ bufsz = 0; - if (_rtpypath) { + if (_rtpypath && _rtpypath[0] != '\0') { size_t rtpypath_len; rtpypath = _Py_char2wchar(_rtpypath, &rtpypath_len); if (rtpypath != NULL) bufsz += rtpypath_len + 1; - else - _rtpypath = NULL; } defpath = _pythonpath;