]> granicus.if.org Git - python/commitdiff
bpo-35346, platform: import subprocess in _syscmd_file() (GH-10892)
authorVictor Stinner <vstinner@redhat.com>
Tue, 4 Dec 2018 16:18:12 +0000 (17:18 +0100)
committerGitHub <noreply@github.com>
Tue, 4 Dec 2018 16:18:12 +0000 (17:18 +0100)
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.

Lib/platform.py

index 98ee06f85ef1579fe653acac55ef7c68b802975b..74346c4cab090c8e9182242929baf7bea83869c0 100755 (executable)
@@ -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')