]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #16309: Make PYTHONPATH= behavior the same as if PYTHONPATH not set at all.
authorAndrew Svetlov <andrew.svetlov@gmail.com>
Sat, 3 Nov 2012 11:52:58 +0000 (13:52 +0200)
committerAndrew Svetlov <andrew.svetlov@gmail.com>
Sat, 3 Nov 2012 11:52:58 +0000 (13:52 +0200)
Thanks to Armin Rigo and Alexey Kachayev.

Lib/test/test_cmd_line.py
Misc/ACKS
Misc/NEWS
Modules/getpath.c

index 7644db21eea791b886087e3ae2c8a632822042c4..cbe1e5545d647a5012efaf9d4374fcf83bc1152f 100644 (file)
@@ -216,6 +216,23 @@ class CmdLineTest(unittest.TestCase):
         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()
index 899df2dd2f423754b82daf929ae048102d1841ab..96d8178b6348debbb00478d4558e7eb990b26c73 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -587,6 +587,7 @@ Sijin Joseph
 Andreas Jung
 Tattoo Mabonzo K.
 Bohuslav Kabrda
+Alexey Kachayev
 Bob Kahn
 Kurt B. Kaiser
 Tamito Kajiyama
index 755e3d11be4f63d259a45602ff521f20408199bc..c6ba38b0a4a8964a87dde7e60e8bf4e8c23f9546 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@ What's New in Python 3.4.0 Alpha 1?
 Core and Builtins
 -----------------
 
+- Issue #16309: Make PYTHONPATH="" behavior the same as if PYTHONPATH
+  not set at all.
+
 - Issue #10189: Improve the error reporting of SyntaxErrors related to global
   and nonlocal statements.
 
index b98c52012d7df7b10b245e1c85036e6e4d024409..be164dfdd41dec5befc609b589069a6aebb44d9e 100644 (file)
@@ -699,13 +699,11 @@ calculate_path(void)
      */
     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;