autoflake icon indicating copy to clipboard operation
autoflake copied to clipboard

not removing imports when a symbol is redeclared

Open gentunian opened this issue 11 months ago • 0 comments

Consider the following example:

from autoflake import fix_code

def fix_code():
    return "this"

print(fix_code())

import from autoflake import fix_code won't be removed. I found this issue while using pymerger and merging multiple files into a single one. For some reason, pymerger is failing in not including imports that should actually not be included, and instead they are included in the file single file (see https://github.com/yamenk-gribaudo/pymerger/issues/2).

So, if you run autoflake on the file to remove unused imports on symbol redefinition, as shown in the snippet above, it won't succeed in remove those imports.

In the example above fix_code from autoflake is not used in the file. What's being used is fix_code defined in the file instead by inner scoping.

gentunian avatar Feb 24 '25 16:02 gentunian