summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorPablo Galindo <Pablogsal@gmail.com>2019-12-23 16:42:48 (GMT)
committerGitHub <noreply@github.com>2019-12-23 16:42:48 (GMT)
commitd69cbeb99d5fd0d5464e937202cca6a2024d1bcf (patch)
treeee2fe8b0241603b1ef96e550023b6a7af85d7b36 /Lib
parent4b3b1226e86df6cd45e921c8f2ad23c3639c43b2 (diff)
downloadcpython-d69cbeb99d5fd0d5464e937202cca6a2024d1bcf.zip
cpython-d69cbeb99d5fd0d5464e937202cca6a2024d1bcf.tar.gz
cpython-d69cbeb99d5fd0d5464e937202cca6a2024d1bcf.tar.bz2
Revert "bpo-38870: Remove dependency on contextlib to avoid performance regression on import (GH-17376)" (GH-17687)
This reverts commit ded8888fbc33011dd39b7b1c86a5adfacc4943f3.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/ast.py19
1 files changed, 6 insertions, 13 deletions
diff --git a/Lib/ast.py b/Lib/ast.py
index 76e0cac..62f6e07 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):