Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions Lib/ast.py
Original file line number Diff line number Diff line change
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