GithubHelp home page GithubHelp logo

albertas / deadcode Goto Github PK

View Code? Open in Web Editor NEW
49.0 49.0 1.0 275 KB

Find and fix unused Python code using command line.

License: GNU Affero General Public License v3.0

Makefile 0.47% Python 99.53%
auto-fix code-quality deadcode lithuanian python unused-code

deadcode's People

Contributors

albertas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

luisdemarchi

deadcode's Issues

Always True ifs are removed

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.

noqa doesn't work for decorated functions

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.

[feat] remove code

@albertas I would like to know if it is possible or if there is a way for me to automatically delete this indicated code?

[fix] library not installed

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'

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

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.