autoimport icon indicating copy to clipboard operation
autoimport copied to clipboard

Broken syntax with multiline, function-local imports

Open hydrargyrum opened this issue 2 years ago • 3 comments

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.

hydrargyrum avatar Oct 03 '23 09:10 hydrargyrum

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?

lyz-code avatar Oct 03 '23 14:10 lyz-code

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

hydrargyrum avatar Oct 03 '23 15:10 hydrargyrum

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

lyz-code avatar Oct 04 '23 11:10 lyz-code