[Python-checkins] cpython: Issue #16309: Make PYTHONPATH= behavior the same as if PYTHONPATH not set at

andrew.svetlov python-checkins at python.org
Sat Nov 3 12:53:08 CET 2012


http://hg.python.org/cpython/rev/05f8f7544f92
changeset: 80186:05f8f7544f92
user: Andrew Svetlov <andrew.svetlov at gmail.com>
date: Sat Nov 03 13:52:58 2012 +0200
summary:
 Issue #16309: Make PYTHONPATH= behavior the same as if PYTHONPATH not set at all.
Thanks to Armin Rigo and Alexey Kachayev.
files:
 Lib/test/test_cmd_line.py | 17 +++++++++++++++++
 Misc/ACKS | 1 +
 Misc/NEWS | 3 +++
 Modules/getpath.c | 4 +---
 4 files changed, 22 insertions(+), 3 deletions(-)
diff --git a/Lib/test/test_cmd_line.py b/Lib/test/test_cmd_line.py
--- a/Lib/test/test_cmd_line.py
+++ b/Lib/test/test_cmd_line.py
@@ -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 --git a/Misc/ACKS b/Misc/ACKS
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -587,6 +587,7 @@
 Andreas Jung
 Tattoo Mabonzo K.
 Bohuslav Kabrda
+Alexey Kachayev
 Bob Kahn
 Kurt B. Kaiser
 Tamito Kajiyama
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@
 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.
 
diff --git a/Modules/getpath.c b/Modules/getpath.c
--- a/Modules/getpath.c
+++ b/Modules/getpath.c
@@ -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;
-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /