Skip to main content

Automatically add code comments to silence the output of pylint

Project description

pylint-silent

Automatically add code comments to silence the output of pylint.

pylint can be very useful in finding software bugs in python code. A good article demonstrating this is Why Pylint is both useful and unusable, and how you can actually use it. In short, when running pylint on existing code, it tends to output tons of messages.

pylint-silent is suppose to make pylint usable. The idea is to automatically add code comments of the form # pylint: disable to silent every pylint message. This will allow you to deploy pylint in a Continuous Integration (CI) setup. If a code commit introduces new pylint messages, these will be visible immediately.

On top of that, all existing pylint messages will show up as comments in the code. When you work on a piece of code and see a pylint comment, you can try to fix it.

Install

pylint-silent can be installed from pypi:

pip install pylint-silent

Usage

The basic workflow for running pylint-silent for the first time is:

pylint my_package > pylint.log
pylint-silent apply pylint.log
pylint my_package  # This should return a perfect 10.00 score.

WARNING: pylint-silent modifies python files in place. It is assumed that you are using some version control system.

For example, if pylint produced this message:

test.py:35:10: W0613: Unused argument 'name' (unused-argument)

pylint-silent would add this comment:

def func(name):  # pylint: disable=unused-argument

If adding the comment would make the line too long, pylint-silent would instead add:

# pylint: disable-next=unused-argument
def very-long-function-name-with-some-arguments(first_argument, second_argument):

--max-line-length specfies the maximum line length. This feature is disabled by default for compatibility with previous versions. It is disabled by having a default maximum line length of 999. In the future the default should change to 88.

Another option is to run pylint-silent --signature to add a signature to each generated comment:

def func(name):  # pylint: disable=unused-argument; silent

This way you can easily identify which comments were generated by pylint-silent.

For subsequent runs, you probably want to clear the old comments first. Assuming you are using signatures:

pylint-silent reset --signature my_package/*.py  # List all python files here
pylint my_package > pylint.log
pylint-silent apply --signature pylint.log

There are two reasons to clear old comments:

  1. Remove stale comments to code that was already fixed.
  2. pylint-silent does not know how to handle lines that already have a # pylint comment in them.

To reset or show statistics on all python files in a folder you might want to use the find command:

find my_package -name "*.py" -exec pylint-silent stats {} +
find my_package -name "*.py" -exec pylint-silent reset {} +

Known limitations

In some cases pylint-silent may break your code:

FAVICON = base64.decodestring("""  # pylint: disable=deprecated-method
...

Luckily, you can simply run pylint a second time to detect such cases. In this case pylint would ignore the comment because it is part of the string. Therefore, the warning message would still show up. This code has to be fixed manually:

FAVICON = base64.decodestring(  # pylint: disable=deprecated-method
"""...

Another issue is that messages that involve multiple files cannot be silenced. I'm aware of two such messages:

  • cyclic-import
  • duplicate-code

You could just disable these messages. Personally I think that these are relevant messages. So instead I just modify pylint score calculation to something like:

evaluation=10.0 + 0.15 - 10 * ((float(5 * error + warning + refactor + convention) / statement) * 10)

The 0.15 artificially raises the score to 10.0 and makes pylint return a success code. The factor of 10 * increases the score sensitivity, which, by default, is way too low even for a medium sized project.

pylint also lets you disable a checks on a block of code:

# pylint: disable=unused-import
import time
import sys
# pylint: enable=unused-import

pylint-silent would ignore these blocks. pylint-silent reset would not clear these messages and pylint-silent stats would not count them.

Alternatives

An alternative solution to pylint noise is pylint-ignore. Whichever option you choose, I recommend reading their documentation about how pylint should be used.

Summary

pylint's motto is: It's not just a linter that annoys you!

pylint-silent helps pylint live up to its motto.

Changelog

1.4.2 (2025-10-07)

  • Update compatible python versions to python 3.9 through 3.14.

1.4.1 (2024-04-28)

  • Preserve file permissions also during reset. Fixes #6.

1.4 (2024-02-11)

  • Update compatible python versions to currently supported python 3.8 through 3.12.

1.3 (2023-05-12)

  • Mark every pylint-silent comment with a signature. Fixes #4. PR #5.
  • Add a --max-line-length option. Fixes #3.
  • Fix tests for pylint 2.16. Require pylint >= 2.16 for the tests.

1.2 (2022-12-23)

  • Preserve comments meant for other non-pylint tools. PR #2.

1.1.2 (2022-11-30)

  • Use pyproject.toml instead of setup.py.
  • Update compatible python versions to currently supported python 3.7 through 3.11.
  • Fix bug in pylint-silent stats that got confused with = symbols in code.
  • Document in README.md how to reset or get statistics on all files in folder.

1.1.1 (2021-04-13)

  • Preserve file permissions in generated code. Fixes #1.

1.1 (2021-03-04)

  • Ignore disable/enable blocks.
  • Add reference to pylint-ignore in the README.
  • Add testing based on pytest and tox.
  • Handle missing-module-docstring correctly.

1.0.1 (2020-07-22)

  • Fix link from pypi.org to github.
  • Fix markdown in README.md.

1.0 (2020-07-20)

  • Initial release.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pylint_silent-1.4.2.tar.gz (16.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pylint_silent-1.4.2-py3-none-any.whl (14.9 kB view details)

Uploaded Python 3

File details

Details for the file pylint_silent-1.4.2.tar.gz.

File metadata

  • Download URL: pylint_silent-1.4.2.tar.gz
  • Upload date:
  • Size: 16.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for pylint_silent-1.4.2.tar.gz
Algorithm Hash digest
SHA256 e7238600de347b58b70e10b7ae0e1bd7db59c58860e10d1b2b65188896b48fd2
MD5 1f5f5cf55215b607c35fb9db952e6123
BLAKE2b-256 ae02d25a37995c8ab7cdfd5584af6e2cf6240ded9afefc0cc666a9d2cf60fdff

See more details on using hashes here.

File details

Details for the file pylint_silent-1.4.2-py3-none-any.whl.

File metadata

  • Download URL: pylint_silent-1.4.2-py3-none-any.whl
  • Upload date:
  • Size: 14.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for pylint_silent-1.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8770fd01b9ca888668d05d60708076caf73e1e1d2dd66920fd7df3a822ffc271
MD5 5fe4031685d21b2bdb5b29fe8f6e9bd2
BLAKE2b-256 9ac55fc25bab20c26159cc46e485b9728b4804a2563ae3ab53c912f586e63c0d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page