LibCST icon indicating copy to clipboard operation
LibCST copied to clipboard

RemoveUnusedImports codemod incorrectly removes this

Open zsol opened this issue 4 years ago • 1 comments

class X:
  import random
  a = [random.lol for _ in ()]

random here is used by the class body, but gets removed by the codemod. This might be because ScopeProvider doesn't connect the access in the list comprehension with the class-local import.

zsol avatar Jul 22 '21 11:07 zsol

OTOH the codemod also removes this import:

from a import b
class X:
  b = 1
  c = b()

Because the imported b clashes with the class-local b variable.

zsol avatar Nov 10 '21 11:11 zsol