8e539b0a0dce — Gerald Klix (pie01) 3 years ago
SUM: Made push accept any sequence of additional arguments.
ADD: Some documentation.
ADD: More doc tests.
2 files changed, 21 insertions(+), 4 deletions(-)

M gf/go.py
M tests/writer_simple.tst
M gf/go.py +12 -4
@@ 235,13 235,13 @@ def __call__(writer: Writer, text: str, 
     else:
         writer.file.write(text)
 
-@method()
-def push(writer: Writer):
+@variadic_method()
+def push(writer: Writer, *ignored_arguments):
     """`Push` has no effect on an ordinary `Writer` instance."""
     pass
 
-@method()
-def pop(writer: Writer):
+@variadic_method()
+def pop(writer: Writer, *ignored_arguments):
     """`Pop` has, like `push`, no effect on an ordinary `Writer` instance."""
     pass
 

          
@@ 299,6 299,10 @@ def __call__(writer: IndentingWriter, te
 
 @method()
 def push(writer: IndentingWriter, steps: int):
+    """Push the old indent on the stack and indent.
+
+    Indentation is `steps` times the writer's indent width.
+    """
     writer.indents.append(writer.indent)
     indent = writer.indent_char * (writer.indent_width * steps)
     writer.indent += indent

          
@@ 307,6 311,7 @@ def push(writer: IndentingWriter, steps:
         
 @method()
 def push(writer: IndentingWriter, indent: str):
+    """Indent by using `indent`."""
     writer.indents.append(writer.indent)
     writer.indent += indent
     if writer.only_newline:

          
@@ 314,15 319,18 @@ def push(writer: IndentingWriter, indent
 
 @method()
 def push(writer: IndentingWriter):
+    """Push the old indent and indent one indent width."""
     push(writer, 1)
 
 @method()
 def pop(writer: IndentingWriter, steps: int):
+    """Pop `steps` levels of indentation."""
     for count in range(steps):
         writer.indent = writer.indents.pop()
 
 @method()
 def pop(writer: IndentingWriter):
+    """Pop one level of indentation."""
     pop(writer, 1)
        
 

          
M tests/writer_simple.tst +9 -0
@@ 93,3 93,12 @@ 1
 <BLANKLINE>
     0
 1
+
+>>> w("0"); push('--'); w(); w("1"); push('++'); w(); w("2")
+>>> pop(2)
+>>> w(); w("3")
+>>> st()
+0
+--1
+--++2
+3
  No newline at end of file