[Python-checkins] Revert "bpo-38870: Remove dependency on contextlib to avoid performance regression on import (GH-17376)" (GH-17687)
Pablo Galindo
webhook-mailer at python.org
Mon Dec 23 11:42:55 EST 2019
https://github.com/python/cpython/commit/d69cbeb99d5fd0d5464e937202cca6a2024d1bcf
commit: d69cbeb99d5fd0d5464e937202cca6a2024d1bcf
branch: master
author: Pablo Galindo <Pablogsal at gmail.com>
committer: GitHub <noreply at github.com>
date: 2019-12-23T16:42:48Z
summary:
Revert "bpo-38870: Remove dependency on contextlib to avoid performance regression on import (GH-17376)" (GH-17687)
This reverts commit ded8888fbc33011dd39b7b1c86a5adfacc4943f3.
files:
M Lib/ast.py
diff --git a/Lib/ast.py b/Lib/ast.py
index 76e0cac838b92..62f6e075a09fd 100644
--- a/Lib/ast.py
+++ b/Lib/ast.py
@@ -597,22 +597,15 @@ def buffer(self):
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):
More information about the Python-checkins
mailing list