[Python-checkins] cpython: Remove redundant imports.

florent.xicluna python-checkins at python.org
Fri Nov 4 08:30:19 CET 2011


http://hg.python.org/cpython/rev/fa82071bb7e1
changeset:   73345:fa82071bb7e1
user:        Florent Xicluna <florent.xicluna at gmail.com>
date:        Fri Nov 04 08:29:17 2011 +0100
summary:
  Remove redundant imports.

files:
  Lib/getpass.py            |  4 +---
  Lib/pickle.py             |  2 +-
  Lib/pstats.py             |  1 -
  Lib/shutil.py             |  1 +
  Lib/site.py               |  3 +--
  Lib/tkinter/__init__.py   |  5 ++---
  Lib/tkinter/filedialog.py |  2 --
  7 files changed, 6 insertions(+), 12 deletions(-)


diff --git a/Lib/getpass.py b/Lib/getpass.py
--- a/Lib/getpass.py
+++ b/Lib/getpass.py
@@ -72,7 +72,7 @@
             finally:
                 termios.tcsetattr(fd, tcsetattr_flags, old)
                 stream.flush()  # issue7208
-        except termios.error as e:
+        except termios.error:
             if passwd is not None:
                 # _raw_input succeeded.  The final tcsetattr failed.  Reraise
                 # instead of leaving the terminal in an unknown state.
@@ -145,8 +145,6 @@
 
     """
 
-    import os
-
     for name in ('LOGNAME', 'USER', 'LNAME', 'USERNAME'):
         user = os.environ.get(name)
         if user:
diff --git a/Lib/pickle.py b/Lib/pickle.py
--- a/Lib/pickle.py
+++ b/Lib/pickle.py
@@ -1326,7 +1326,7 @@
     return doctest.testmod()
 
 if __name__ == "__main__":
-    import sys, argparse
+    import argparse
     parser = argparse.ArgumentParser(
         description='display contents of the pickle files')
     parser.add_argument(
diff --git a/Lib/pstats.py b/Lib/pstats.py
--- a/Lib/pstats.py
+++ b/Lib/pstats.py
@@ -674,7 +674,6 @@
                 return stop
             return None
 
-    import sys
     if len(sys.argv) > 1:
         initprofile = sys.argv[1]
     else:
diff --git a/Lib/shutil.py b/Lib/shutil.py
--- a/Lib/shutil.py
+++ b/Lib/shutil.py
@@ -15,6 +15,7 @@
 
 try:
     import bz2
+    del bz2
     _BZ2_SUPPORTED = True
 except ImportError:
     _BZ2_SUPPORTED = False
diff --git a/Lib/site.py b/Lib/site.py
--- a/Lib/site.py
+++ b/Lib/site.py
@@ -154,7 +154,7 @@
                 if not dircase in known_paths and os.path.exists(dir):
                     sys.path.append(dir)
                     known_paths.add(dircase)
-            except Exception as err:
+            except Exception:
                 print("Error processing line {:d} of {}:\n".format(n+1, fullname),
                       file=sys.stderr)
                 for record in traceback.format_exception(*sys.exc_info()):
@@ -241,7 +241,6 @@
         return USER_SITE
 
     from sysconfig import get_path
-    import os
 
     if sys.platform == 'darwin':
         from sysconfig import get_config_var
diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py
--- a/Lib/tkinter/__init__.py
+++ b/Lib/tkinter/__init__.py
@@ -1159,7 +1159,6 @@
         return (e,)
     def _report_exception(self):
         """Internal function."""
-        import sys
         exc, val, tb = sys.exc_info()
         root = self._root()
         root.report_callback_exception(exc, val, tb)
@@ -1663,7 +1662,7 @@
         # ensure that self.tk is always _something_.
         self.tk = None
         if baseName is None:
-            import sys, os
+            import os
             baseName = os.path.basename(sys.argv[0])
             baseName, ext = os.path.splitext(baseName)
             if ext not in ('.py', '.pyc', '.pyo'):
@@ -1737,7 +1736,7 @@
             exec(open(base_py).read(), dir)
     def report_callback_exception(self, exc, val, tb):
         """Internal function. It reports exception on sys.stderr."""
-        import traceback, sys
+        import traceback
         sys.stderr.write("Exception in Tkinter callback\n")
         sys.last_type = exc
         sys.last_value = val
diff --git a/Lib/tkinter/filedialog.py b/Lib/tkinter/filedialog.py
--- a/Lib/tkinter/filedialog.py
+++ b/Lib/tkinter/filedialog.py
@@ -306,7 +306,6 @@
     def _fixresult(self, widget, result):
         if result:
             # keep directory and filename until next time
-            import os
             # convert Tcl path objects to strings
             try:
                 result = result.string
@@ -333,7 +332,6 @@
             # multiple results:
             result = tuple([getattr(r, "string", r) for r in result])
             if result:
-                import os
                 path, file = os.path.split(result[0])
                 self.options["initialdir"] = path
                 # don't set initialfile or filename, as we have multiple of these

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list