How do I disable a Pylint warning?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
You can disable a Pylint warning at several scopes: one line, a block, a whole file, or the project configuration. The best choice depends on whether the warning is a one-off false positive or a rule your project intentionally does not want to enforce.
Disable a Warning Inline
For a single line, add a pylint: disable= comment.
This is the narrowest possible suppression and is usually the safest because it documents the exception exactly where it occurs.
You can disable multiple warnings on the same line too:
Disable and Re-Enable Around a Block
If a warning applies to a short region rather than one line, disable it before the block and re-enable it afterward.
This is more precise than disabling the rule for the entire file.
Disable a Warning for a Whole File
If a file intentionally violates a rule throughout, place the directive near the top.
File-level suppression should be used carefully. It is sometimes appropriate for generated code, compatibility shims, or legacy modules, but it is usually too broad for routine development.
Use Message Names or Numeric Codes
Pylint warnings can be referred to by symbolic name or numeric code. Symbolic names are usually easier to understand and maintain.
Examples:
- '
unused-argument' - '
no-member' - '
missing-function-docstring'
A symbolic disable comment is easier to review than a numeric code that readers have to look up later.
Disable Rules in Configuration
If the whole project wants to relax a rule, put that decision in configuration rather than scattering disable comments everywhere.
In .pylintrc or pyproject.toml, depending on your setup, you can configure disabled messages globally.
Example .pylintrc style:
This is appropriate when the team has intentionally decided not to enforce a rule project-wide.
Prefer Narrow Scope Over Broad Scope
A good rule of thumb is:
- one line if the issue is local
- block if a small section genuinely needs it
- file only when the whole file is special
- project config only when the team agrees the rule is not useful globally
This keeps suppressions honest and prevents a temporary exception from quietly turning into a permanent blind spot.
Suppression Should Be Explained When Non-Obvious
If the reason for disabling is not immediately clear, add a short explanation nearby.
That makes the suppression easier to review later and less likely to be mistaken for careless lint avoidance.
Common Pitfalls
The most common mistake is disabling warnings too broadly, especially at file or project scope, when a single-line suppression would have been enough. Another is using disable comments without understanding what the warning was trying to say in the first place. Developers also forget to remove old suppressions after refactoring, so the codebase accumulates stale exceptions that no longer serve a purpose.
Summary
- Use
# pylint: disable=warning-namefor narrow suppressions. - Prefer symbolic warning names over numeric codes.
- Re-enable warnings after a block when the exception is temporary and local.
- Put project-wide rule decisions in config instead of repeated inline comments.
- Treat suppression as an exception that should stay as small and as well-explained as possible.

