deshaw / pyflyby

A set of productivity tools for Python
https://deshaw.github.io/pyflyby/
Other
348 stars 52 forks source link

tidy-imports incorrectly removes import when used in decorator and matches with a parameter name (PyInf#11068) #265

Closed sac111gp closed 7 months ago

sac111gp commented 1 year ago

tidy-imports incorrectly removes import when used in decorator and matches with a parameter name

import random

def repeat(times):
    def wrap(fn):
        def wrap_wrap(*args, **kwargs):
            for i in range(times):
                fn(*args, **kwargs)
        return wrap_wrap
    return wrap

@repeat(random.choice([1, 4]))
def foo(random):
    print(random)
$ tidy-imports repro.py
...
-import random
...