Skip to content

Commit 62e32d6

Browse files
Issue python#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.
1 parent daeddc4 commit 62e32d6

3 files changed

Lines changed: 11 additions & 5 deletions

File tree

Lib/test/test_trace.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,11 +311,11 @@ def test_coverage(self):
311311
with captured_stdout() as stdout:
312312
self._coverage(tracer)
313313
stdout = stdout.getvalue()
314-
self.assertTrue("pprint.py" in stdout)
315-
self.assertTrue("case.py" in stdout) # from unittest
314+
self.assertIn("pprint.py", stdout)
315+
self.assertIn("case.py", stdout) # from unittest
316316
files = os.listdir(TESTFN)
317-
self.assertTrue("pprint.cover" in files)
318-
self.assertTrue("unittest.case.cover" in files)
317+
self.assertIn("pprint.cover", files)
318+
self.assertIn("unittest.case.cover", files)
319319

320320
def test_coverage_ignore(self):
321321
# Ignore all files, nothing should be traced nor printed

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ Release date: TBA
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #19398: Extra slash no longer added to sys.path components in case of
14+
empty compile-time PYTHONPATH components.
15+
1316
- Issue #28426: Fixed potential crash in PyUnicode_AsDecodedObject() in debug
1417
build.
1518

Modules/getpath.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,10 @@ calculate_path(void)
762762

763763
if (defpath[0] != SEP) {
764764
wcscat(buf, prefix);
765-
wcscat(buf, separator);
765+
if (prefixsz >= 2 && prefix[prefixsz - 2] != SEP &&
766+
defpath[0] != (delim ? DELIM : L'\0')) { /* not empty */
767+
wcscat(buf, separator);
768+
}
766769
}
767770

768771
if (delim) {

0 commit comments

Comments
 (0)