diff -r 3d7000549eb1 Lib/shutil.py --- a/Lib/shutil.py Wed Jan 23 03:01:23 2013 -0800 +++ b/Lib/shutil.py Wed Jan 23 16:02:12 2013 +0200 @@ -1084,7 +1084,11 @@ return cmd return None - path = (path or os.environ.get("PATH", os.defpath)).split(os.pathsep) + if path is None: + path = os.environ.get("PATH", os.defpath) + if not path: + return None + path = path.split(os.pathsep) if sys.platform == "win32": # The current directory takes precedence on Windows. diff -r 3d7000549eb1 Lib/test/test_shutil.py --- a/Lib/test/test_shutil.py Wed Jan 23 03:01:23 2013 -0800 +++ b/Lib/test/test_shutil.py Wed Jan 23 16:02:12 2013 +0200 @@ -1352,6 +1352,20 @@ rv = shutil.which(self.temp_file.name[:-4], path=self.dir) self.assertEqual(rv, self.temp_file.name[:-4] + ".EXE") + def test_environ_path(self): + with support.EnvironmentVarGuard() as env: + env['PATH'] = self.dir + rv = shutil.which(self.file) + self.assertEqual(rv, self.temp_file.name) + + def test_empty_path(self): + base_dir = os.path.dirname(self.dir) + with support.temp_cwd(path=self.dir), \ + support.EnvironmentVarGuard() as env: + env['PATH'] = self.dir + rv = shutil.which(self.file, path='') + self.assertIsNone(rv) + class TestMove(unittest.TestCase): diff -r 3d7000549eb1 Misc/NEWS --- a/Misc/NEWS Wed Jan 23 03:01:23 2013 -0800 +++ b/Misc/NEWS Wed Jan 23 16:02:12 2013 +0200 @@ -220,6 +220,9 @@ Library ------- +- Issue #17012: shutil.which() no longer fallbacks to the PATH environment + variable if empty path argument is specified. + - Issue #12411: Fix to cgi.parse_multipart to correctly use bytes boundaries and bytes data. Patch by Jonas Wagner.