Revert "bpo-38870: Remove dependency on contextlib to avoid performance regression on import (GH-17376)" (GH-17687)
This reverts commit ded8888fbc
.
This commit is contained in:
parent
4b3b1226e8
commit
d69cbeb99d
19
Lib/ast.py
19
Lib/ast.py
|
@ -597,22 +597,15 @@ class _Unparser(NodeVisitor):
|
||||||
self._buffer.clear()
|
self._buffer.clear()
|
||||||
return value
|
return value
|
||||||
|
|
||||||
class _Block:
|
@contextmanager
|
||||||
|
def block(self):
|
||||||
"""A context manager for preparing the source for blocks. It adds
|
"""A context manager for preparing the source for blocks. It adds
|
||||||
the character':', increases the indentation on enter and decreases
|
the character':', increases the indentation on enter and decreases
|
||||||
the indentation on exit."""
|
the indentation on exit."""
|
||||||
def __init__(self, unparser):
|
self.write(":")
|
||||||
self.unparser = unparser
|
self._indent += 1
|
||||||
|
yield
|
||||||
def __enter__(self):
|
self._indent -= 1
|
||||||
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)
|
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def delimit(self, start, end):
|
def delimit(self, start, end):
|
||||||
|
|
Loading…
Reference in New Issue