docformatter unnecessarily replaces tab characters with spaces. When a file
uses tabs, running docformatter on it changes indentation characters both
inside docstrings and in code outside the docstring.
Reproducer
def some_function(
a_parameter
):
"""Important documentation.
with an indented item
"""
...
$ docformatter file.py
--- before/file.py
+++ after/file.py
@@ -1,8 +1,8 @@
def some_function(
- a_parameter
+ a_parameter
):
"""Important documentation.
- with an indented item
- """
+ with an indented item
+ """
...
Cause
Two independent code paths substitute spaces for the original indentation
characters:
-
_do_add_formatted_docstring and _do_add_unformatted_docstring build
the indent for the docstring's internal lines as " " * token.start[1],
based on the docstring's opening line. When the opening line is indented with
a tab, each tab inside the docstring is replaced by a single space.
-
_do_format_code runs the whole file through tokenize.untokenize,
which reconstructs inter-token whitespace as " " * col_offset. This means
that tabs on continuation lines are also replaced by a single space.
docformatterunnecessarily replaces tab characters with spaces. When a fileuses tabs, running
docformatteron it changes indentation characters bothinside docstrings and in code outside the docstring.
Reproducer
Cause
Two independent code paths substitute spaces for the original indentation
characters:
_do_add_formatted_docstringand_do_add_unformatted_docstringbuildthe indent for the docstring's internal lines as
" " * token.start[1],based on the docstring's opening line. When the opening line is indented with
a tab, each tab inside the docstring is replaced by a single space.
_do_format_coderuns the whole file throughtokenize.untokenize,which reconstructs inter-token whitespace as
" " * col_offset. This meansthat tabs on continuation lines are also replaced by a single space.