From: Pablo Galindo Date: Mon, 23 Dec 2019 16:42:48 +0000 (+0000) Subject: Revert "bpo-38870: Remove dependency on contextlib to avoid performance regression... X-Git-Tag: v3.9.0a3~197 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d69cbeb99d5fd0d5464e937202cca6a2024d1bcf;p=thirdparty%2FPython%2Fcpython.git Revert "bpo-38870: Remove dependency on contextlib to avoid performance regression on import (GH-17376)" (GH-17687) This reverts commit ded8888fbc33011dd39b7b1c86a5adfacc4943f3. --- diff --git a/Lib/ast.py b/Lib/ast.py index 76e0cac838b9..62f6e075a09f 100644 --- a/Lib/ast.py +++ b/Lib/ast.py @@ -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):