Repository: asottile/astpretty

Issue:
Have an option for indent argument to be number of spaces
Like `json.dumps` or `ast.dump`, making indent have an option to be an integer would be nice.

I could probably make a PR for this, if the idea gets approval.

Discussion:
tusharsadhwani: There is one failing test on my system:

```
❯ pytest
============================= test session starts ==============================
platform linux -- Python 3.9.1, pytest-6.2.1, py-1.10.0, pluggy-0.13.1
rootdir: /home/tushar/code/python/astpretty
collected 28 items                                                             

tests/astpretty_test.py ................F...........                     [100%]

=================================== FAILURES ===================================
______________ test_pformat_nested_node_without_line_information _______________

    def test_pformat_nested_node_without_line_information():
        expected_38 = (
            'Subscript(\n'
            '    lineno=1,\n'
            '    col_offset=0,\n'
            '    end_lineno=1,\n'
            '    end_col_offset=4,\n'
            "    value=Name(lineno=1, col_offset=0, end_lineno=1, end_col_offset=1, id='a', ctx=Load()),\n"  # noqa: E501
            '    slice=Index(\n'
            '        value=Constant(lineno=1, col_offset=2, end_lineno=1, end_col_offset=3, value=0, kind=None),\n'  # noqa: E501
            '    ),\n'
            '    ctx=Load(),\n'
            ')'
        )
        expected_lt38 = (
            'Subscript(\n'
            '    lineno=1,\n'
            '    col_offset=0,\n'
            "    value=Name(lineno=1, col_offset=0, id='a', ctx=Load()),\n"
            '    slice=Index(\n'
            '        value=Num(lineno=1, col_offset=2, n=0),\n'
            '    ),\n'
            '    ctx=Load(),\n'
            ')'
        )
        expected = expected_38 if sys.version_info >= (3, 8) else expected_lt38
        ret = astpretty.pformat(_to_expr_value('a[0]'))
>       assert ret == expected
E       AssertionError: assert 'Subscript(\n...tx=Load(),\n)' == 'Subscript(\n...tx=Load(),\n)'
E         Skipping 175 identical leading characters in diff, use -v to show
E         -     slice=Index(
E         -         value=Constant(lineno=1, col_offset=2, end_lineno=1, end_col_offset=3, value=0, kind=None),
E         ?     ^^^^^^ ^
E         +     slice=Constant(lineno=1, col_offset=2, end_lineno=1, end_col_offset=3, value=0, kind=None),
E         ?     ^ ^^
E         -     ),...
E         
E         ...Full output truncated (3 lines hidden), use '-vv' to show

tests/astpretty_test.py:172: AssertionError
=========================== short test summary info ============================
FAILED tests/astpretty_test.py::test_pformat_nested_node_without_line_information
========================= 1 failed, 27 passed in 0.18s =========================
```

Which I'm unsure about.
asottile: the test output needs to be updated for python3.9 -- `Index` is gone and has been replaced with just the value

Patch:
diff --git a/astpretty.py b/astpretty.py
index d0c1b59..abc8444 100644
--- a/astpretty.py
+++ b/astpretty.py
@@ -75,7 +75,7 @@ def _leaf(node: 'ASTType', show_offsets: bool = True) -> str:
 
 def pformat(
         node: Union['ASTType', None, str],
-        indent: str = '    ',
+        indent: Union[str, int] = '    ',
         show_offsets: bool = True,
         _indent: int = 0,
 ) -> str:
@@ -86,6 +86,11 @@ def pformat(
     elif _is_leaf(node):
         return _leaf(node, show_offsets=show_offsets)
     else:
+        if isinstance(indent, int):
+            indent_s = indent * ' '
+        else:
+            indent_s = indent
+
         class state:
             indent = _indent
 
@@ -96,7 +101,7 @@ def pformat(
             state.indent -= 1
 
         def indentstr() -> str:
-            return state.indent * indent
+            return state.indent * indent_s
 
         def _pformat(el: Union['ASTType', None, str], _indent: int = 0) -> str:
             return pformat(


Test patch:
diff --git a/tests/astpretty_test.py b/tests/astpretty_test.py
index b595d64..796950f 100644
--- a/tests/astpretty_test.py
+++ b/tests/astpretty_test.py
@@ -127,6 +127,21 @@ def test_pformat_custom_indent():
     )
 
 
+def test_pformat_integer_indent():
+    node = _to_expr_value('[a, b, c]')
+    ret = astpretty.pformat(node, indent=3, show_offsets=False)
+    assert ret == (
+        'List(\n'
+        '   elts=[\n'
+        "      Name(id='a', ctx=Load()),\n"
+        "      Name(id='b', ctx=Load()),\n"
+        "      Name(id='c', ctx=Load()),\n"
+        '   ],\n'
+        '   ctx=Load(),\n'
+        ')'
+    )
+
+
 def test_pformat_nested_node_without_line_information():
     expected_38 = (
         'Subscript(\n'