/usr/lib/python3/dist-packages/pylama/errors.py is in python3-pylama 7.3.3-1.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | """ Don't duplicate same errors from different linters. """
import re
from collections import defaultdict
PATTERN_NUMBER = re.compile(r'^[A-Z]\d+$')
DUPLICATES = (
# multiple statements on one line
[('pycodestyle', 'E701'), ('pylint', 'C0321')],
[('pep8', 'E701'), ('pylint', 'C0321')],
# unused variable
[('pylint', 'W0612'), ('pyflakes', 'W0612')],
# undefined variable
[('pylint', 'E0602'), ('pyflakes', 'E0602')],
# unused import
[('pylint', 'W0611'), ('pyflakes', 'W0611')],
# whitespace before ')'
[('pylint', 'C0326'), ('pycodestyle', 'E202')],
[('pylint', 'C0326'), ('pep8', 'E202')],
# whitespace before '('
[('pylint', 'C0326'), ('pycodestyle', 'E211')],
[('pylint', 'C0326'), ('pep8', 'E211')],
# multiple spaces after operator
[('pylint', 'C0326'), ('pycodestyle', 'E222')],
[('pylint', 'C0326'), ('pep8', 'E222')],
# missing whitespace around operator
[('pylint', 'C0326'), ('pycodestyle', 'E225')],
[('pylint', 'C0326'), ('pep8', 'E225')],
# unexpected spaces
[('pylint', 'C0326'), ('pycodestyle', 'E251')],
[('pylint', 'C0326'), ('pep8', 'E251')],
# long lines
[('pylint', 'C0301'), ('pycodestyle', 'E501')],
[('pylint', 'C0301'), ('pep8', 'E501')],
# statement ends with a semicolon
[('pylint', 'W0301'), ('pycodestyle', 'E703')],
[('pylint', 'W0301'), ('pep8', 'E703')],
# multiple statements on one line
[('pylint', 'C0321'), ('pycodestyle', 'E702')],
# bad indentation
[('pylint', 'W0311'), ('pycodestyle', 'E111')],
[('pylint', 'W0311'), ('pep8', 'E111')],
# wildcart import
[('pylint', 'W00401'), ('pyflakes', 'W0401')],
# module docstring
[('pydocstyle', 'D100'), ('pylint', 'C0111')],
[('pep257', 'D100'), ('pylint', 'C0111')],
)
DUPLICATES = dict((key, values) for values in DUPLICATES for key in values)
def remove_duplicates(errors):
""" Filter duplicates from given error's list. """
passed = defaultdict(list)
for error in errors:
key = error.linter, error.number
if key in DUPLICATES:
if key in passed[error.lnum]:
continue
passed[error.lnum] = DUPLICATES[key]
yield error
class Error(object):
""" Store an error's information. """
def __init__(self, linter="", col=1, lnum=1, type="E",
text="unknown error", filename="", number="", **kwargs):
""" Init error information with default values. """
text = ' '.join(str(text).strip().split('\n'))
if linter:
text = "%s [%s]" % (text, linter)
number = number or text.split(' ', 1)[0]
if not PATTERN_NUMBER.match(number):
number = ""
self._info = dict(linter=linter, col=col, lnum=lnum, type=type[:1],
text=text, filename=filename, number=number)
def __getattr__(self, name):
return self._info[name]
def __getitem__(self, name):
return self._info[name]
def get(self, name, default=None):
""" Implement dictionary `get` method. """
return self._info.get(name, default)
def __repr__(self):
return "<Error: %s %s>" % (self.number, self.linter)
# pylama:ignore=W0622,D,R0924
|