Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Incorrect indentation after reduce_operators process #19

Open
spinash opened this issue Jun 19, 2023 · 1 comment
Open

Incorrect indentation after reduce_operators process #19

spinash opened this issue Jun 19, 2023 · 1 comment

Comments

@spinash
Copy link

spinash commented Jun 19, 2023

with source file contain this (for reproducing the problem) :

class test():
    def test():
        s=func()
        (s).test = "test"
        print a
    def test2(b):
        print b

I have this error :

# pyminifier  --outfile /tmp/file.py src/test.py 
Traceback (most recent call last):
  File "/usr/local/bin/pyminifier", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/pyminifier/__main__.py", line 202, in main
    pyminify(options, files)
  File "/usr/local/lib/python3.11/dist-packages/pyminifier/__init__.py", line 332, in pyminify
    source = minification.minify(tokens, options)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/pyminifier/minification.py", line 432, in minify
    result = dedent(result, use_tabs=options.tabs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/pyminifier/minification.py", line 315, in dedent
    for i, tok in enumerate(tokenize.generate_tokens(io_obj.readline)):
  File "/usr/lib/python3.11/tokenize.py", line 516, in _tokenize
    raise IndentationError(
  File "<tokenize>", line 6
    def test2(b):
IndentationError: unindent does not match any outer indentation level

After reduce_operators function (https://github.com/dzhuang/pyminifier3/blob/main/pyminifier/minification.py#L428)
I've write result into file, and this is the result :

class test():
    def test():
        s=func()
(s).test="test"
        print a
    def test2(b):
        print b

Probably the function reduce_operators remove all space before parenthesis and indentation is not correct after processing

@dzhuang
Copy link
Owner

dzhuang commented Jun 20, 2023

Hi @spinash , as mentioned in readme, this repo is not recommended and thus I will not maintain it, please consider python-minifier instead.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants