summaryrefslogtreecommitdiff
path: root/Lib/platform.py
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2018-12-04 17:18:12 +0100
committerGitHub <noreply@github.com>2018-12-04 17:18:12 +0100
commitb8e689a6e8134e88f857a55e50b6a4977967e385 (patch)
tree25fa93df9fd3f3e930b7c16a76885ad4e9ab44e3 /Lib/platform.py
parent4752e65250bce60b97d5af702d586092d02fbf58 (diff)
downloadcpython-git-b8e689a6e8134e88f857a55e50b6a4977967e385.tar.gz
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.
Diffstat (limited to 'Lib/platform.py')
-rwxr-xr-xLib/platform.py12
1 files changed, 7 insertions, 5 deletions
diff --git a/Lib/platform.py b/Lib/platform.py
index 98ee06f85e..74346c4cab 100755
--- a/Lib/platform.py
+++ b/Lib/platform.py
@@ -113,9 +113,9 @@ __copyright__ = """
__version__ = '1.0.8'
import collections
-import sys, os, re, subprocess
-
-import warnings
+import os
+import re
+import sys
### Globals & Constants
@@ -612,11 +612,13 @@ def _syscmd_file(target, default=''):
if sys.platform in ('dos', 'win32', 'win16'):
# XXX Others too ?
return default
+
+ import subprocess
target = _follow_symlinks(target)
try:
proc = subprocess.Popen(['file', target],
- stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
-
+ stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT)
except (AttributeError, OSError):
return default
output = proc.communicate()[0].decode('latin-1')