From 1e4b73fcf75a27c7e9020ecb8e58ffc274909e5a Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Fri, 11 Nov 2016 12:11:55 +0200 Subject: Issue #19398: Extra slash no longer added to sys.path components in case of empty compile-time PYTHONPATH components. This fixes some tests in -S or -I modes. --- Lib/test/test_trace.py | 8 ++++---- Misc/NEWS | 3 +++ Modules/getpath.c | 5 ++++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Lib/test/test_trace.py b/Lib/test/test_trace.py index 2292ad6..4971fcd 100644 --- a/Lib/test/test_trace.py +++ b/Lib/test/test_trace.py @@ -293,11 +293,11 @@ class TestCoverage(unittest.TestCase): with captured_stdout() as stdout: self._coverage(tracer) stdout = stdout.getvalue() - self.assertTrue("pprint.py" in stdout) - self.assertTrue("case.py" in stdout) # from unittest + self.assertIn("pprint.py", stdout) + self.assertIn("case.py", stdout) # from unittest files = os.listdir(TESTFN) - self.assertTrue("pprint.cover" in files) - self.assertTrue("unittest.case.cover" in files) + self.assertIn("pprint.cover", files) + self.assertIn("unittest.case.cover", files) def test_coverage_ignore(self): # Ignore all files, nothing should be traced nor printed diff --git a/Misc/NEWS b/Misc/NEWS index aa00448..d136f2b 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,9 @@ What's New in Python 2.7.13? Core and Builtins ----------------- +- Issue #19398: Extra slash no longer added to sys.path components in case of + empty compile-time PYTHONPATH components. + - Issue #21720: Improve exception message when the type of fromlist is unicode. fromlist parameter of __import__() only accepts str in Python 2 and this will help to identify the problem especially when the unicode_literals diff --git a/Modules/getpath.c b/Modules/getpath.c index 18b161c..c42ce31 100644 --- a/Modules/getpath.c +++ b/Modules/getpath.c @@ -597,7 +597,10 @@ calculate_path(void) if (defpath[0] != SEP) { strcat(buf, prefix); - strcat(buf, separator); + if (prefixsz >= 2 && prefix[prefixsz - 2] != SEP && + defpath[0] != (delim ? DELIM : L'\0')) { /* not empty */ + strcat(buf, separator); + } } if (delim) { -- cgit v0.12