Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Lib/shutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -1608,6 +1608,7 @@ def which(cmd, mode=os.F_OK | os.X_OK, path=None):
path.
"""
cmd = os.fspath(cmd)
Comment thread
picnixz marked this conversation as resolved.
Resolved
use_bytes = isinstance(cmd, bytes)

# If we're given a path with a directory part, look it up directly rather
Expand Down
4 changes: 4 additions & 0 deletions Lib/test/test_shutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -2614,6 +2614,10 @@ def test_basic(self):
rv = shutil.which(self.file, path=self.dir)
self.assertEqual(rv, self.filepath)

def test_pathlike_cmd(self):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good: this test is run on Unicode string (TestWhich) and bytes string (TestWhichBytes).

rv = shutil.which(FakePath(self.file), path=self.dir)
self.assertEqual(rv, self.filepath)

def test_absolute_cmd(self):
# When given the fully qualified path to an executable that exists,
# it should be returned.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix :func:`shutil.which` for path-like command objects whose
:meth:`~os.PathLike.__fspath__` method returns :class:`bytes`.
Loading