autoflake remove global variables python

327 views Asked by At

I am trying autoflake to remove unused global variable from source code. It is able to remove unused import but not the global variables: example:

import autoflake
code = """
import os
import math
x = 1
#unused list
agg_level = [
    "a",
    (
        "abc",
        "def",
        "xyz",
        "pqr",
    ),
]
print(x)
"""
print(
    autoflake.fix_code(
        code, 
        remove_all_unused_imports=True, 
        remove_duplicate_keys=True, 
        remove_unused_variables=True
    )
)

output

x = 1
unused list
agg_level = [
    "a",
    (
        "abc",
        "def",
        "xyz",
        "pqr",
    ),
]
print(x)
0

There are 0 answers