python-minifier icon indicating copy to clipboard operation
python-minifier copied to clipboard

Feature Request: Whitespace Minification and Line Merging Options

Open hunyanjie opened this issue 5 months ago • 2 comments

Hi,

I hope the tool could support whitespace minification for each line of code, similar to what pyminifier does. For example, the original code:

def test(name):
    return f"Hello, {name}!"

name = input("Enter your name: ")
if name != "":
    print(test(name))
else:
    print("Please enter your name")

Should be minified to:

def test(name):
 return f"Hello, {name}!"
name=input("Enter your name: ")
if name!="":
 print(test(name))
else:
 print("Please enter your name")

Additionally, I would like to request two more features:

  1. Line Merging Option: It would be great if there could be an option to merge lines (default behavior could be to merge).

  2. Indentation Choice: It would be useful if users could choose whether to use tabs or spaces for indentation.

Thanks!

hunyanjie avatar Jul 25 '25 05:07 hunyanjie

Hello, python-minifier tries to make optimal choices to minimize the size of the output, in bytes.

In particular, it uses tabs for indentation because they are a still a single byte but are more readable that a single space.

Similarly, newlines are only output if they are required, or when using them increases readability without increasing the size of the output.

Using your example code, the output is:

def test(name):return f"Hello, {name}!"
name=input('Enter your name: ')
if name!='':print(test(name))
else:print('Please enter your name')

Which by placing things on the same lines, doesn't need any indentation at all.

Can you say more about what you would use these options for?

dflook avatar Jul 25 '25 10:07 dflook

Thank you for your response. Here's a bit more about why I think these options would be useful:

  • User Control Over Code Style:

Some users might prefer to avoid excessive line merging to maintain readability in certain parts of the code. For example, they might want to remove comments or perform less aggressive code shortening to facilitate easier modifications later on. Allowing users to choose whether to merge lines would give them better control over balancing code size and readability.

  • Custom Indentation Options:

Different projects or teams often have specific coding standards. Some prefer tab indentation, while others prefer spaces. Providing a choice between tabs and spaces would make the tool more versatile and adaptable to various coding styles.

I believe these features would enhance the flexibility and usability of the tool. Thanks for considering my suggestions!

hunyanjie avatar Jul 27 '25 05:07 hunyanjie