liftoff / pyminifier

Pyminifier is a Python code minifier, obfuscator, and compressor.
GNU General Public License v3.0
1.47k stars 224 forks source link

One line functions appends a pass, breaking the indentation #102

Open vlachoudis opened 6 years ago

vlachoudis commented 6 years ago

When obfuscating one lien function like def square(x): return x**2 it append a pass below, which breaks the code like

def S(a): return a**2
   pass
erelson commented 5 years ago

Another odd symptom, it doesn't do this always. I have four defined in a row, with the following result (also, just minifying; not obfuscating):

Before

if sysname == 'linux' or sysname == 'win32':
    # Mocks for non-pyboard use
    import time
    def ticks_us(): return (time.time()%1.e4)*1.e6
    def ticks_diff(x, y): return x - y
    def sleep_us(x): return time.sleep(x/1.e6)
    def sleep_ms(x): return time.sleep(x/1.e3)
    #Bus = lambda x: x
    from unittest.mock import Mock, MagicMock

After:

if sysname=='linux' or sysname=='win32':
 import time
 def ticks_us():return(time.time()%1.e4)*1.e6
  pass
 def ticks_diff(x,y):return x-y
 def sleep_us(x):return time.sleep(x/1.e6)
  pass
 def sleep_ms(x):return time.sleep(x/1.e3)
 from unittest.mock import Mock,MagicMock

Oh well, making them not one-liners is a good enough workaround.