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

Suggestion

Open tthn0 opened this issue 4 years ago • 3 comments

This:

from pymongo import MongoClient

connection_str = 'connection_str'

cluster = MongoClient(connection_str)

database = cluster['db']

collection = database['col']

document = collection.find()

if document['_id'] == 123:
    print('ok')

By default turns into:

from pymongo import MongoClient as A
B='connection_str'
C=A(B)
D=C['db']
E=D['col']
F=E.find()
if F['_id']==123:print('ok')

But it could easily be more compact to save a few more bytes like so:

from pymongo import MongoClient as A
if A('connection_str')['db']['col'].find()['_id']==123:print('ok')

Also, please make an option to turn into a one-liner for all possible statements! (Separated by semicolons)

Edit to make my previous sentence clearer: although the output size wouldn't change, please add a "one-liner" option to separate statements by semicolons instead of newlines where possible

tthn0 avatar Apr 18 '21 06:04 tthn0

These are both good ideas!

Currently python-minifier prefers to use newlines where possible instead of semicolons for readability, but I can see how a one-liner would be more useful.

dflook avatar Apr 18 '21 09:04 dflook

how about adding semicolons for the obfuscation, makes it harder for reverse engineering. this reduces the space further in indented blocks because semicolons reduce the requirement to indent in certain locations.

amk200 avatar Apr 22 '21 04:04 amk200

@xcodz-dot Semicolons are already used in indented blocks. Newlines would only be used at the module level, where it makes no difference to the output size.

dflook avatar Apr 22 '21 08:04 dflook