python-minifier
python-minifier copied to clipboard
Fix: Ensure ModulePrinter respects the indent_char argument
This PR fixes a bug in ModulePrinter where the indent_char argument specified during initialization was being ignored.
Currently, the printer defaults to using a tab character (\t) for indentation, regardless of the character provided to the indent_char argument. This change ensures that the specified indent_char is correctly used when generating the output source code.
Verification
The following example demonstrates the corrected behavior.
import ast
from python_minifier.module_printer import ModulePrinter
module = ast.parse("def f():\n while True:\n print('hello')")
# Initialize the printer with a single space as the indent_char
printer = ModulePrinter(indent_char=" ")
result = printer(module)
# The expected output should use a space for indentation
expected = "def f():\n while True:print('hello')"
# Before this fix, the result was:
# "def f():\n\twhile True:print('hello')"
assert result == expected