pyminifier icon indicating copy to clipboard operation
pyminifier copied to clipboard

Indentation issue after removing docstrings

Open EricBrunel opened this issue 9 years ago • 1 comments

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 avatar Sep 23 '16 13:09 EricBrunel

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.

EricBrunel avatar Sep 26 '16 08:09 EricBrunel