Skip to content

Commit b8e689a

Browse files
authored
bpo-35346, platform: import subprocess in _syscmd_file() (GH-10892)
Only platform._syscmd_file() uses subprocess. Move subprocess import inside this function to reduce the number of imports at Python startup. Remove also warnings import which is no longer needed.
1 parent 4752e65 commit b8e689a

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

Lib/platform.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@
113113
__version__ = '1.0.8'
114114

115115
import collections
116-
import sys, os, re, subprocess
117-
118-
import warnings
116+
import os
117+
import re
118+
import sys
119119

120120
### Globals & Constants
121121

@@ -612,11 +612,13 @@ def _syscmd_file(target, default=''):
612612
if sys.platform in ('dos', 'win32', 'win16'):
613613
# XXX Others too ?
614614
return default
615+
616+
import subprocess
615617
target = _follow_symlinks(target)
616618
try:
617619
proc = subprocess.Popen(['file', target],
618-
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
619-
620+
stdout=subprocess.PIPE,
621+
stderr=subprocess.STDOUT)
620622
except (AttributeError, OSError):
621623
return default
622624
output = proc.communicate()[0].decode('latin-1')

0 commit comments

Comments
 (0)