deadcode icon indicating copy to clipboard operation
deadcode copied to clipboard

[bug]: Deadcode --fix removes the `f` character from the `from` keyword in `from module import (a,b,c,)`

Open vpatov opened this issue 2 years ago • 0 comments

deadcode version:

[[package]]
name = "deadcode"
version = "2.2.2"
description = "Find and remove dead code."
category = "dev"
optional = false
python-versions = ">=3.8"
files = [
    {file = "deadcode-2.2.2-py3-none-any.whl", hash = "sha256:d8280cf44e224e47e061f9b9963b902c009dc1ba1e43a42623a43ab88e1afa36"},
    {file = "deadcode-2.2.2.tar.gz", hash = "sha256:b63e207999667e731212e04f6d48888a2e3f7256e5ee808ba9082af20d99dca0"},
]

Python version:

Python 3.11.7

To reproduce, create the following two files in the same directory:

file1.py:

foo = 1
bar = 2
xyz = 3

file2.py:

from file1 import (
    foo,
    bar,
    xyz
)

from file1 import foo

def fn():
    pass

fn()

Run deadcode with --fix

🐍 v3.11.7 (myapp-py3.11) 
✗  deadcode ./file2.py --fix
file2.py:1:0: DC007 Import `bar` is never used
file2.py:1:0: DC007 Import `foo` is never used
file2.py:1:0: DC007 Import `xyz` is never used
file2.py:7:0: DC007 Import `foo` is never used

Removed 4 unused code items!

I expect all of the imports to be removed, but this what file2.py looks like afterwards instead:

rom file1 import (
    foo,
    bar,
    xyz
)

def fn():
    pass

fn()

It removes the f in from, and doesn't get rid of those imports.

vpatov avatar Jan 21 '24 20:01 vpatov