liftoff / pyminifier

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

Indentation issue after removing docstrings #75

Open EricBrunel opened 7 years ago

EricBrunel commented 7 years ago

Very simple example with the following file:

class MyClass(object):
  first_variable = 42

  """Second variable docstring."""
  _second_variable = 'foo'

The result of the minification is:

class MyClass(object):
 first_variable=42
  _second_variable='foo'

The second variable is not indented correctly: there's an extra space. So the minified code doesn't compile.

EricBrunel commented 7 years ago

I think I found the reason: in the file minification.py, line 94, the removal of the training newline seems to mess up the line numbers, and the rebuilding of the text from the tokens in token_utils.py / untokenize produces the wrong output. Commenting out line 94 in minification.py seems to solve the problem. This will probably leave an unneeded empty line in the text, but it will be removed afterwards anyway, so no big deal, I guess.