]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Revert "bpo-38870: Remove dependency on contextlib to avoid performance regression...
authorPablo Galindo <Pablogsal@gmail.com>
Mon, 23 Dec 2019 16:42:48 +0000 (16:42 +0000)
committerGitHub <noreply@github.com>
Mon, 23 Dec 2019 16:42:48 +0000 (16:42 +0000)
This reverts commit ded8888fbc33011dd39b7b1c86a5adfacc4943f3.

Lib/ast.py

index 76e0cac838b924479626330f3afbc3d31dd1a641..62f6e075a09fdf2a3f23927b16756f87f1d33df7 100644 (file)
@@ -597,22 +597,15 @@ class _Unparser(NodeVisitor):
         self._buffer.clear()
         return value
 
-    class _Block:
+    @contextmanager
+    def block(self):
         """A context manager for preparing the source for blocks. It adds
         the character':', increases the indentation on enter and decreases
         the indentation on exit."""
-        def __init__(self, unparser):
-            self.unparser = unparser
-
-        def __enter__(self):
-            self.unparser.write(":")
-            self.unparser._indent += 1
-
-        def __exit__(self, exc_type, exc_value, traceback):
-            self.unparser._indent -= 1
-
-    def block(self):
-        return self._Block(self)
+        self.write(":")
+        self._indent += 1
+        yield
+        self._indent -= 1
 
     @contextmanager
     def delimit(self, start, end):