Skip to content

Commit 339a16e

Browse files
committed
ENH: Remove Python 2 compatibility from imported pyperclip code
Remove the fallback to which/where that is only necessary for Python 2 that does not feature shutil.which(). Also collapse the imports to avoid importing shutil.which() twice. It is now only imported as `_executable_exists()` to minimize the changes to the original code.
1 parent 59e26b7 commit 339a16e

File tree

1 file changed

+2
-21
lines changed

1 file changed

+2
-21
lines changed

pandas/io/clipboard/__init__.py

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131
Cygwin is currently not supported.
3232
3333
Security Note: This module runs programs with these names:
34-
- which
35-
- where
3634
- pbcopy
3735
- pbpaste
3836
- xclip
@@ -59,7 +57,7 @@
5957
)
6058
import os
6159
import platform
62-
from shutil import which
60+
from shutil import which as _executable_exists
6361
import subprocess
6462
import time
6563
import warnings
@@ -83,23 +81,6 @@
8381

8482
ENCODING = "utf-8"
8583

86-
try:
87-
from shutil import which as _executable_exists
88-
except ImportError:
89-
# The "which" unix command finds where a command is.
90-
if platform.system() == "Windows":
91-
WHICH_CMD = "where"
92-
else:
93-
WHICH_CMD = "which"
94-
95-
def _executable_exists(name):
96-
return (
97-
subprocess.call(
98-
[WHICH_CMD, name], stdout=subprocess.PIPE, stderr=subprocess.PIPE
99-
)
100-
== 0
101-
)
102-
10384

10485
class PyperclipTimeoutException(PyperclipException):
10586
pass
@@ -571,7 +552,7 @@ def determine_clipboard():
571552
return init_windows_clipboard()
572553

573554
if platform.system() == "Linux":
574-
if which("wslconfig.exe"):
555+
if _executable_exists("wslconfig.exe"):
575556
return init_wsl_clipboard()
576557

577558
# Setup for the macOS platform:

0 commit comments

Comments
 (0)