dflook / python-minifier

Transform Python source code into its most compact representation
MIT License
558 stars 41 forks source link

Function names are not changed for some files #22

Closed fersarr closed 3 years ago

fersarr commented 3 years ago

Hi, thanks for this really useful tool.

I have been testing it with some of my files and I see that for some files, the function names get changed but for some they don't. Unfortunately I can't paste the one that doesn't get the names changed. Do you have any reason in mind as to why that could be happening? If not, I will put more work into trying to create a working example that I can share.

For this file, however, the functions do get renamed:

# test_file.py
global_var = 3

def test_function(prep_text, entites):
    '''
    test comment
    '''
    # single line comment
    test_var_name = {
        'blabla': '1',
        'blabla2': '2'
    }

    myset = {'one', 'two', 'three'}
    print(myset)

    return test_var_name

def test_func_1(var1):
    print('bla')

def test_func_2(var2):
    test_func_1(var1)

def test_func_3(var1):
    test_func_2('blabla')
$ pyminify --remove-literal-statements --rename-globals --no-hoist-literals test_file.py
C=print
D=3
def E(prep_text,entites):A={'blabla':'1','blabla2':'2'};B={'one','two','three'};C(B);return A
def A(var1):C('bla')
def B(var2):A(var1)
def F(var1):B('blabla')
fersarr commented 3 years ago

hm interesting, local variables are also not getting renamed in that bigger file I mentioned.

dflook commented 3 years ago

Hi @fersarr, There are two likely reasons for this:

Can you narrow it down to one of these?

fersarr commented 3 years ago

aha! perfect. Yes, I removed a from <module> import * and it started renaming everything. Thanks a lot!