lyz-code / autoimport

Autoimport automatically fixes wrong import statements.
https://lyz-code.github.io/autoimport
GNU General Public License v3.0
97 stars 24 forks source link

Broken syntax with multiline, function-local imports #250

Open hydrargyrum opened 1 year ago

hydrargyrum commented 1 year ago

Description

Steps to reproduce

Input file:

from foo import bar

class C(bar.C):
    def method(self, param):
        from foo.some_very_long_name_of_a_module.another_submodule.wait_for_it import (
            yet_another_long_name
        )

        yet_another_long_name(param)

Run autoimport on that file.

Current behavior

Output file:

from foo import bar

        from foo.some_very_long_name_of_a_module.another_submodule.wait_for_it import (
            yet_another_long_name
)

class C(bar.C):
    def method(self, param):

        yet_another_long_name(param)

Desired behavior

Syntax is not broken. Import moved correctly (or not moved, see #249)

Environment

autoimport 1.3.3

By the way, neither make version nor python -c "import autoimport.version; print(autoimport.version.version_info())" do work with pipx, I used pipx list, which is a bit rigid.

lyz-code commented 1 year ago

Hi @hydrargyrum thanks for taking the time to open another issue. I can reproduce the issue, will you be able to submit a PR to fix it?

hydrargyrum commented 1 year ago

Ok, I'll try but I can't promise yet I'll understand how to do it!

lyz-code commented 1 year ago

Lovely <3, if you have any question I'd do my best to answer them