[Python-checkins] bpo-35346, platform: import subprocess in _syscmd_file() (GH-10892)
Victor Stinner
webhook-mailer at python.org
Tue Dec 4 11:18:16 EST 2018
https://github.com/python/cpython/commit/b8e689a6e8134e88f857a55e50b6a4977967e385
commit: b8e689a6e8134e88f857a55e50b6a4977967e385
branch: master
author: Victor Stinner <vstinner at redhat.com>
committer: GitHub <noreply at github.com>
date: 2018-12-04T17:18:12+01:00
summary:
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.
files:
M Lib/platform.py
diff --git a/Lib/platform.py b/Lib/platform.py
index 98ee06f85ef1..74346c4cab09 100755
--- a/Lib/platform.py
+++ b/Lib/platform.py
@@ -113,9 +113,9 @@
__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')
More information about the Python-checkins
mailing list