Rules
Ignoring checks with noqa comments
Inline # noqa comments can be used to ignore deadcode checks.
E.g. unused Foo class wont be detected/fixed because # noqa: DC03 comment is used:
class Foo: # noqa: DC03
pass
For a decorated function, method, property, or class, place the comment on the physical line of the def, async def, or class keyword:
@cache
def foo(): # noqa: DC02
pass
A comment on the first decorator line is still accepted.
Rules
Code |
Name |
Message |
|---|---|---|
DC01 |
unused-variable |
Variable |
DC02 |
unused-function |
Function |
DC03 |
unused-class |
Class |
DC04 |
unused-method |
Method |
DC05 |
unused-attribute |
Attribute |
DC06 |
unused-name |
Name |
DC07 |
unused-import |
Import |
DC08 |
unused-property |
Property |
DC09 |
unreachable-body |
Unreachable body of a conditional statement or loop |
DC11 |
empty-file |
Empty Python file |
DC12 |
commented-out-code |
Commented out code |
DC13 |
unreachable-code |
Code after terminal statement, e.g. |
DC |
ignore-expression |
Do not show any findings for an expression, which starts on current line (this code can only be used in |
Ignoring rules globally
Use --ignore to suppress findings for one or more rule codes for the whole run:
deadcode . --ignore DC12
The same option can be set in pyproject.toml:
[tool.deadcode]
ignore = ["DC12"]
A pre-commit hook can pass the option through args:
repos:
- repo: https://github.com/albertas/deadcode
rev: v2.6.3
hooks:
- id: deadcode
args: [--ignore, DC12]
Ignoring unittest lifecycle methods
unittest lifecycle methods (setUp, tearDown, setUpClass, tearDownClass, asyncSetUp, asyncTearDown, setUpModule, tearDownModule) declared in test files are ignored by default, alongside the existing pytest hooks.
Declarations with those names outside test files are still reported as unused code.
Ignoring Django test lifecycle methods
Django test lifecycle methods (setUpTestData, the django.test.TestCase class method invoked by the framework, and the internal hooks _pre_setup, _post_teardown, _fixture_setup, _fixture_teardown) declared in test files are ignored by default.
Declarations with those names outside test files are still reported as unused code.
Django helpers that your test code invokes itself are not suppressed, so an unreferenced assertContains, assertNumQueries, settings, modify_settings, or captureOnCommitCallbacks is still reported.