albertas / deadcode Goto Github PK
View Code? Open in Web Editor NEWFind and fix unused Python code using command line.
License: GNU Affero General Public License v3.0
Find and fix unused Python code using command line.
License: GNU Affero General Public License v3.0
Nice package. I did run into the following problem. When I try to run deadcode --fix on the following
a=0
if True:
a=1
print(a)
print(a)
then it changes it to
a=0
print(a)
The expected behaviour would be
a=0
a=1
print(a)
print(a)
or just leaving the if
intact.
With an unused function, this works:
def check(arg): # noqa: DC002
pass
but this doesn't:
@cache
def check(arg): # noqa: DC002
pass
This works again, but I don't think it should be valid:
@cache # noqa: DC002
def check(arg):
pass
Adding more decorators yields an error again.
@albertas I would like to know if it is possible or if there is a way for me to automatically delete this indicated code?
After installing your library I needed to manually install "tomli" library
Traceback (most recent call last):
File "/Users/luis/.pyenv/versions/lambda_poc_ai/bin/deadcode", line 5, in <module>
from deadcode.cli import main
File "/Users/luis/.pyenv/versions/3.10.12/envs/lambda_poc_ai/lib/python3.10/site-packages/deadcode/cli.py", line 5, in <module>
from deadcode.actions.parse_arguments import parse_arguments
File "/Users/luis/.pyenv/versions/3.10.12/envs/lambda_poc_ai/lib/python3.10/site-packages/deadcode/actions/parse_arguments.py", line 9, in <module>
import tomli as tomllib
ModuleNotFoundError: No module named 'tomli'
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.