DebugClients/Python/coverage/backward.py

changeset 6219
d6c795b5ce33
parent 5178
878ce843ca9f
--- a/DebugClients/Python/coverage/backward.py	Sat Apr 07 13:17:06 2018 +0200
+++ b/DebugClients/Python/coverage/backward.py	Sat Apr 07 13:35:10 2018 +0200
@@ -3,10 +3,8 @@
 
 """Add things to old Pythons so I can pretend they are newer."""
 
-# This file does lots of tricky stuff, so disable a bunch of pylint warnings.
-# pylint: disable=redefined-builtin
+# This file does tricky stuff, so disable a pylint warning.
 # pylint: disable=unused-import
-# pylint: disable=no-name-in-module
 
 import sys
 
@@ -19,11 +17,14 @@
 except ImportError:
     from io import StringIO
 
-# In py3, ConfigParser was renamed to the more-standard configparser
+# In py3, ConfigParser was renamed to the more-standard configparser.
+# But there's a py3 backport that installs "configparser" in py2, and I don't
+# want it because it has annoying deprecation warnings. So try the real py2
+# import first.
 try:
+    import ConfigParser as configparser
+except ImportError:
     import configparser
-except ImportError:
-    import ConfigParser as configparser
 
 # What's a string called?
 try:
@@ -45,7 +46,7 @@
 
 # range or xrange?
 try:
-    range = xrange
+    range = xrange      # pylint: disable=redefined-builtin
 except NameError:
     range = range
 
@@ -58,18 +59,29 @@
     # in Python versions earlier than 3.3.
     from pipes import quote as shlex_quote
 
-# A function to iterate listlessly over a dict's items.
+# A function to iterate listlessly over a dict's items, and one to get the
+# items as a list.
 try:
     {}.iteritems
 except AttributeError:
+    # Python 3
     def iitems(d):
         """Produce the items from dict `d`."""
         return d.items()
+
+    def litems(d):
+        """Return a list of items from dict `d`."""
+        return list(d.items())
 else:
+    # Python 2
     def iitems(d):
         """Produce the items from dict `d`."""
         return d.iteritems()
 
+    def litems(d):
+        """Return a list of items from dict `d`."""
+        return d.items()
+
 # Getting the `next` function from an iterator is different in 2 and 3.
 try:
     iter([]).next
@@ -143,6 +155,12 @@
     PYC_MAGIC_NUMBER = imp.get_magic()
 
 
+def invalidate_import_caches():
+    """Invalidate any import caches that may or may not exist."""
+    if importlib and hasattr(importlib, "invalidate_caches"):
+        importlib.invalidate_caches()
+
+
 def import_local_file(modname, modfile=None):
     """Import a local file as a module.
 

eric ide

mercurial