Skip to main content

More signal, less noise.

Project description

logo

Pylint-Ignore

More signal, less noise.

Project/Repo:

MIT License Supported Python Versions CalVer 2020.1006 PyPI Version PyPI Downloads

Code Quality/CI:

Build Status Type Checked with mypy Code Coverage Code Style: sjfmt

Name role since until
Manuel Barkhau (mbarkhau@gmail.com) author/maintainer 2020-06 -

Developer Ergonomics

The main issue with pylint is developer ergonomics. The messages produced by pylint can be valuable, but you have to put in some work before you can enable it in your CI setup. If you have an established codebase, you'll probably have to research its configuration options, disable many invalid messages and/or blindly litter your code with pylint:disable comments.

The goal of pylint-ignore is to let you benefit from pylint right now, without having to first wade through endless message noise and without having to delay using it because you don't have time to configure every detail.

How it Works

The pylint-ignore command is a thin wrapper around the pylint command.

$ pip install pylint-ignore
Installing collected packages: astroid,isort,pylint,pylint-ignore
...
Successfully installed pylint-ignore-2020.1004

Assuming you have a minimal configuration such as this setup.cfg.

You can invoke pylint-ignore like this:

$ pylint-ignore --rcfile=setup.cfg src/
************* Module src/mymodule.py
src/mymodule.py:290:0: W0102: Dangerous default value sys.argv[1:] (builtins.list) as argument (dangerous-default-value)
...

-------------------------------------------------------------------
Your code has been rated at 9.92/10 (previous run: 10.00/10, -0.08)

The pylint-ignore command reads its own configuration file called pylint-ignore.md. This file contains messages that should be ignored and it is automatically updated with new entries if you specify the --update-ignorefile parameter.

$ pylint-ignore --rcfile=setup.cfg src/ --update-ignorefile
-------------------------------------------------------------------
Your code has been rated at 10.00/10 (previous run: 9.92/10, +0.08)

The original message no longer shows up in the output, and it is instead logged in the pylint-ignore.md, which will now look something like this:

$ grep --after-context=15 --max-count=1 "## File" pylint-ignore.md

## File src/mymodule.py - Line 290 - W0102 (dangerous-default-value)

- message: Dangerous default value sys.argv[1:] (builtins.list) as argument
- author : Manuel Barkhau <mbarkhau@gmail.com>
- date   : 2020-07-17T21:15:25

```
  289:
> 290: def main(args: Sequence[str] = sys.argv[1:]) -> ExitCode:
  291:     try:
```

The exception to this behaviour is with error messages. Any message with the message type (E) error, for probable bugs in the code will not be added to the ignore file. These are very likely to point to a bug and should not be swept under the rug. For all other messages, as your time permits, the recommended approach to using pylint-ignore is the following:

  1. If a message refers to a valid issue, update your code rather than ignoring the message.
  2. If a message should always be ignored (globally), then to do so via the usual pylintrc or setup.cfg files rather than this pylint-ignore.md file.
  3. If a message is a false positive, add a comment of this form to your code: # pylint:disable=<symbol> ; explain why this is a false positive

In principal these are the same options you have with pylint by itself. For this particular case I would prefer option 3.:

def main(args: Sequence[str] = sys.argv[1:]) -> ExitCode:
    # pylint:disable=dangerous-default-value; args is not mutated, mypy ensures this
    try:

With this change, when you run pylint-ignore --update-ignorefile again, the entry in pylint-ignore.md is removed.

What does this solve?

Problem1: Setup Cost

If you have a large existing project, your codebase will inevitably trigger many linting messages the first time you use pylint. You might take a first pass and try to reduce the noise. During this first pass, you will encounter two issues:

  1. You will be overwhelmed at all the configuration options that you will need before you can trust that the output of pylint is meaningful.
  2. You will find messages that might be useful in general, but after looking at particular cases, you find that the message is only useful sometimes.

An example of case 1. is perhaps the missing-function-docstring message. You know that is going to be way more work than is justified for your project. Even if you could justify the work in principle and agree that the message is valid, if you did enabled it, you may find a pattern like this emerge:

def get_author_name() -> str:
    """Gets the author name and returns it as a string."""

In case it isn't obvious, the above doc-string is redundant because it adds no information that isn't already in the function signature. In other words, your colleagues are likely to pacify the linter by changing the code in ways that are at best a useless waste of time and at worst they are counterproductive.

Problem2: Time Constraint

As you investigate messages, you will inevitably run across some that you disagree with, if not in general, then at least for the particular cases you're dealing with. Take for example this message:

R0902 Too many instance attributes (10/7) (too-many-instance-attributes)

Where you put the cutoff for "too-many" is a subjective matter. I would caution against code-golfing such cases, just to satisfy the linter. It's a good message to have in general, if for no other reason than to wag a finger when somebody introduces some smelly code. Such a message can be a nudge to investigate further if there are reasonable ways to refactor the code and improve it.

With pylint-ignore you have a file in your repository that serves as a reminder of such cases, until you have time to look at them. In the meantime, because any new messages generated by pylint are not ignored, if any new code is introduced that is similarly smelly, you can catch it in your CI build.

CLI Usage

The pylint-ignore ignore command does not have its own help message. The --help argument will simply behave exactly the same as pylint --help. These are the parameters the pylint-ignore supports:

Usage: pylint-ignore [options]

Options:
  --ignorefile=<FILE>    Path to ignore file [default: pylint-ignore.md]
  --update-ignorefile    Update the ignorefile, adds new messages,
                         removes any messages that are no longer
                         emmitted by pylint (were fixed or disabled)

Normally the pylint-ignore command will not update the pylint-ignore.md file. This is appropriate for

  • CI/CD build systems, where you want to report any issues that were newly introduced.
  • Normal development, when you don't want to introduce any new issues.

If you fix an issue or explicitly disable a message, you can cleanup obsolete entries by adding the --update-ignorefile argument.

$ pylint-ignore --update-ignorefile --ignorefile=etc/pylint-ignore.md \
    --rc-file=setup.cfg src/ test/

Usually changes in line numbers will be detected and not cause your build to fail, but occasionally a message that was previously tracked may no longer be recognized. This can happen for example after you move some code to a different file. For such cases you may also want to use --update-ignorefile (or deal with the actual issue while you're refactoring...).

Changelog for https://gitlab.com/mbarkhau/pylint-ignore

2020.1006

  • Don't ignore messages of type (E) error, for probable bugs in the code

2020.1003

  • 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-ignore-2020.1006.tar.gz (23.0 kB view details)

Uploaded Source

Built Distribution

pylint_ignore-2020.1006-py2.py3-none-any.whl (17.2 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file pylint-ignore-2020.1006.tar.gz.

File metadata

  • Download URL: pylint-ignore-2020.1006.tar.gz
  • Upload date:
  • Size: 23.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1.post20200616 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3

File hashes

Hashes for pylint-ignore-2020.1006.tar.gz
Algorithm Hash digest
SHA256 3627e6cc5d24a31ead87e06d7e84583c0c8f0f067e7b2f0dcc33c42ad316303b
MD5 7d084f28b86fb945ca6be74b1a58bb89
BLAKE2b-256 210b3b7a5dc82d42075e3c72a70f83fc2b32ce4d6fc9daa539ec1b9935457a1b

See more details on using hashes here.

File details

Details for the file pylint_ignore-2020.1006-py2.py3-none-any.whl.

File metadata

  • Download URL: pylint_ignore-2020.1006-py2.py3-none-any.whl
  • Upload date:
  • Size: 17.2 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1.post20200616 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3

File hashes

Hashes for pylint_ignore-2020.1006-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 9df8c205ac9c6cdbd534e2bc2babd6ac31e85c868bcbf0df4f4254a38b817aeb
MD5 ef6d8204ddd9a83f324c58180b4455c9
BLAKE2b-256 568ceb822454023da2ca98f100986b6305ece47b4a6724e381d6dafcfac0168a

See more details on using hashes here.

Supported by

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