Skip to main content

Build Status PyPI version

pydelinter

Pydelinter automatically generates unified-diffs of python source code that violate certain class of Pylint warnings. You can run this tool on your source code, inspect the diffs and apply the diffs as patches.

Installation

pip install pydelinter

Usage

$ delint -h
usage: delint [-h] [--msg_id MSG_ID] [--version] [-v] [-vv]
              file_path_or_folder

Command line tool for delinting certain pylint messages

positional arguments:
  file_path_or_folder  Path to a .py file or folder contain *.py files. This
                       relative path will be used to generate the unified diff
                       files.

optional arguments:
  -h, --help           show this help message and exit
  --msg_id MSG_ID      The pylint message that will be delinterd. Eg W0611
  --version            show program's version number and exit
  -v, --verbose        set loglevel to INFO
  -vv, --very-verbose  set loglevel to DEBUG

Examples:

            Running the below examples will generate an unified-diff file that can be used as a patch to apply the changes to git or Mercurial.
            delinter/main.py --msg W0611 foo/core.py

            To process multiple python files, provide a folder
            delinter/main.py --msg W0611 foo/

            Running, this command on the test file available with this repository:
            delinter/main.py --msg W0611 delinter/test/input

            --- a/delinter/test/input/test_unused_imports.py
            +++ b/delinter/test/input/test_unused_imports.py
            @@ -1,12 +1,7 @@
            -import unitest.mock.patch, unittest.mock.patch as p1
             import unitest.mock.patch, unittest.mock.patch as p2
            -import unittest as t, unittest as t2
            +import unittest as t2
             import unitest.mock.patch as p
            -import os
            -import pandas as pd, numpy as np
            -from collections.abc import defaultdict, OrderedDict
            -from itertools import filterfalse as _filterfalse
            -from collections.abc import x, y
            +from collections.abc import y
             from collections import *

             p2.mock() # use p2

Status of pylint messages supported

Message Id Message Status
W0611 unused-imports :heavy_check_mark:
W0404 reimported :heavy_check_mark:
W0108 unnecessary-lambda
W0107 unnecessary-pass
E1111 assignment-from-no-return
E0701 bad-except-order
E0711 not-implemented-raised
C0411 wrong-import-order
C0412 ungrouped-imports
C0410 multiple-imports
W0611 unused-variable
W0613 unused-argument
W0612 unused-wildcard-import
W0602 global-variable-not-assigned
R0102 simplifiable-if-statement
C0326 bad-whitespace
C0304 missing-final-newline
C0327 multiple-statements
C0305 trailing-newline
C0303 trailing-whitespace
C0325 superfluous-parens

(more items will be added to this list after carefully reviewing all message groups supported by Pylint)

Objectives of this tool

  1. The tool will only support addressing one pytlint warning/error at a time. This is provided through the msg_id argument.
  2. Any warnings that might need complex formatting will not be supported. We leave that to more sophisticated tools like Black.

Caveats

  1. When dropping statements, preceeding newlines/comments attached to the statement will be removed.
  2. Given how pylint reports warnings, the tool might have to be run on the same code base more than once, after applying the previous patch. For example, an (reimported) error on a particular statement, precededs an (unused-import) error. Therefore, re-running the program will force this statement to be tagged by pylint as an unused-import.
  3. The diffs produces by this tool is only as good as how pylint reports warning/errors and howthe LibCST yields the CST. Therefore, manual review of the patches is always a good idea (along with a good test suite).

Acknowledgements

This project has been set up using PyScaffold 3.2.3. For details and usage information on PyScaffold see https://pyscaffold.org/.

This library primarily depends upon the LibCST [https://github.com/Instagram/LibCST] library.

Release files for pydelinter 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pydelinter 0.0.3
File Size Uploaded
pydelinter-0.0.3.tar.gz 22.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pydelinter 0.0.3
File Interpreter ABI Platform
pydelinter-0.0.3-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 34.9 kB

Release files / pydelinter-0.0.3.tar.gz

Download URL pydelinter-0.0.3.tar.gz
Size 22.9 kB
Tags Source
SHA-256 checksum
How to use checksums
893077edb42585d3ddbcc5c1061c7790aef8b752f2b41139d14da99bf600078d
BLAKE2b-256 checksum
How to use checksums
1171e9810e5cbaaa2e6fd9bfc3c18f923f6f3986d1f2cf6d1979e7aa5719099d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.8.3

Release files / pydelinter-0.0.3-py2.py3-none-any.whl

Download URL pydelinter-0.0.3-py2.py3-none-any.whl
Size 11.9 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
c7b5f5517e976a79b8060a8ee61c7e5df4f5bffedac4fae1b31a9db52fc4e950
BLAKE2b-256 checksum
How to use checksums
b2b85c6210c33580eb2ff61d3854faf9ec2a1df4f573f7f892c4cd7fc5671421
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.8.3

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 release files

0.0.2

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page