Skip to content

Commit

Permalink
Revert "bpo-38870: Remove dependency on contextlib to avoid performan…
Browse files Browse the repository at this point in the history
…ce regression on import (pythonGH-17376)"

This reverts commit ded8888.
  • Loading branch information
pablogsal committed Dec 23, 2019
1 parent 4b3b122 commit 2010642
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions Lib/ast.py
Expand Up @@ -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):
Expand Down

0 comments on commit 2010642

Please sign in to comment.