eric7/Plugins/CheckerPlugins/CodeStyleChecker/Simplify/ast_unparse.py

branch
eric7
changeset 8435
f3554a0a34ca
parent 8312
800c432b34c8
--- a/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Simplify/ast_unparse.py	Sat Jun 19 16:22:11 2021 +0200
+++ b/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Simplify/ast_unparse.py	Sun Jun 20 18:31:39 2021 +0200
@@ -13,10 +13,38 @@
 import ast
 import sys
 from enum import IntEnum, auto
-from contextlib import contextmanager, nullcontext
+from contextlib import contextmanager
 
 import AstUtilities
 
+try:
+    from contextlib import nullcontext
+except ImportError:
+    # 'nullcontext'' was defined in Python 3.7. The following code is a copy
+    # of that class.
+    
+    from contextlib import AbstractContextManager
+    
+    class nullcontext(AbstractContextManager):
+        """Context manager that does no additional processing.
+
+        Used as a stand-in for a normal context manager, when a particular
+        block of code is only sometimes used with a normal context manager:
+
+        cm = optional_cm if condition else nullcontext()
+        with cm:
+            # Perform operation, using optional_cm if condition is True
+        """
+
+        def __init__(self, enter_result=None):
+            self.enter_result = enter_result
+
+        def __enter__(self):
+            return self.enter_result
+
+        def __exit__(self, *excinfo):
+            pass
+
 # Large float and imaginary literals get turned into infinities in the AST.
 # We unparse those infinities to INFSTR.
 _INFSTR = "1e" + repr(sys.float_info.max_10_exp + 1)

eric ide

mercurial