Skip to content

Commit

Permalink
Remove the concept of checker priority (#6034)
Browse files Browse the repository at this point in the history
Co-authored-by: Pierre Sassoulas <[email protected]>
  • Loading branch information
DanielNoord and Pierre-Sassoulas authored Apr 1, 2022
1 parent f46904a commit e01fa86
Show file tree
Hide file tree
Showing 31 changed files with 5 additions and 48 deletions.
2 changes: 2 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ Release date: TBA

Closes #1555

* The concept of checker priority has been removed.

* ``duplicate-argument-name`` now only raises once for each set of duplicated arguments.

* Fix bug where specifically enabling just ``await-outside-async`` was not possible.
Expand Down
4 changes: 0 additions & 4 deletions doc/how_tos/custom_checkers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ Firstly we will need to fill in some required boilerplate:
__implements__ = IAstroidChecker
name = "unique-returns"
priority = -1
msgs = {
"W0001": (
"Returns a non-unique constant.",
Expand All @@ -76,9 +75,6 @@ So far we have defined the following required components of our checker:
* A name. The name is used to generate a special configuration
section for the checker, when options have been provided.

* A priority. This must be to be lower than 0. The checkers are ordered by
the priority when run, from the most negative to the most positive.

* A message dictionary. Each checker is being used for finding problems
in your code, the problems being displayed to the user through **messages**.
The message dictionary should specify what messages the checker is
Expand Down
2 changes: 2 additions & 0 deletions doc/whatsnew/2.14.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ Extensions
Other Changes
=============

* The concept of checker priority has been removed.

* Fix false negative for ``no-member`` when attempting to assign an instance
attribute to itself without any prior assignment.

Expand Down
2 changes: 0 additions & 2 deletions examples/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ class MyAstroidChecker(BaseChecker):

# The name defines a custom section of the config for this checker.
name = "custom"
# The priority indicates the order that pylint will run the checkers.
priority = -1
# This class variable declares the messages (ie the warnings and errors)
# that the checker can emit.
msgs = {
Expand Down
1 change: 0 additions & 1 deletion pylint/checkers/classes/class_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,6 @@ class ClassChecker(BaseChecker):
name = "classes"
# messages
msgs = MSGS
priority = -2
# configuration options
options = (
(
Expand Down
1 change: 0 additions & 1 deletion pylint/checkers/classes/special_methods_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ class SpecialMethodsChecker(BaseChecker):
"of the form tuple(tuple, dict)",
),
}
priority = -2

def __init__(self, linter=None):
super().__init__(linter)
Expand Down
1 change: 0 additions & 1 deletion pylint/checkers/design_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,6 @@ class MisdesignChecker(BaseChecker):
name = "design"
# messages
msgs = MSGS
priority = -2
# configuration options
options = (
(
Expand Down
1 change: 0 additions & 1 deletion pylint/checkers/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ class ExceptionsChecker(checkers.BaseChecker):

name = "exceptions"
msgs = MSGS
priority = -4
options = (
(
"overgeneral-exceptions",
Expand Down
1 change: 0 additions & 1 deletion pylint/checkers/imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,6 @@ class ImportsChecker(DeprecatedMixin, BaseChecker):

name = "imports"
msgs = MSGS
priority = -2
default_deprecated_modules = ()

options = (
Expand Down
1 change: 0 additions & 1 deletion pylint/checkers/modified_iterating_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ class ModifiedIterationChecker(checkers.BaseChecker):
}

options = ()
priority = -2

@utils.check_messages(
"modified-iterating-list", "modified-iterating-dict", "modified-iterating-set"
Expand Down
1 change: 0 additions & 1 deletion pylint/checkers/newstyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class NewStyleConflictChecker(BaseChecker):
name = "newstyle"
# messages
msgs = MSGS
priority = -2
# configuration options
options = ()

Expand Down
1 change: 0 additions & 1 deletion pylint/checkers/non_ascii_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class NonAsciiNameChecker(base_checker.BaseChecker):
"""

__implements__ = interfaces.IAstroidChecker
priority = -1

msgs = {
"C2401": (
Expand Down
1 change: 0 additions & 1 deletion pylint/checkers/refactoring/implicit_booleaness_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ class ImplicitBooleanessChecker(checkers.BaseChecker):
),
}

priority = -2
options = ()

@utils.check_messages("use-implicit-booleaness-not-len")
Expand Down
2 changes: 0 additions & 2 deletions pylint/checkers/refactoring/refactoring_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,8 +469,6 @@ class RefactoringChecker(checkers.BaseTokenChecker):
),
)

priority = 0

def __init__(self, linter=None):
super().__init__(linter)
self._return_nodes = {}
Expand Down
1 change: 0 additions & 1 deletion pylint/checkers/typecheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,6 @@ class TypeChecker(BaseChecker):
name = "typecheck"
# messages
msgs = MSGS
priority = -1
# configuration options
options = (
(
Expand Down
1 change: 0 additions & 1 deletion pylint/checkers/unicode.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,6 @@ class UnicodeChecker(pylint.checkers.BaseChecker):
"""

__implements__ = pylint.interfaces.IRawChecker
priority = -1

name = "unicode_checker"

Expand Down
1 change: 0 additions & 1 deletion pylint/checkers/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,6 @@ class VariablesChecker(BaseChecker):

name = "variables"
msgs = MSGS
priority = -1
options = (
(
"init-import",
Expand Down
2 changes: 0 additions & 2 deletions pylint/config/arguments_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ def _register_options_provider(self, provider: "checkers.BaseChecker") -> None:
argument = _convert_option_to_argument(opt, optdict)
self._add_arguments_to_parser(provider.name, argument)

# pylint: disable-next=fixme
# TODO: Do something with option provider priorities (see OptionsManagerMixIn.register_options_provider)
# pylint: disable-next=fixme
# TODO: Do something with option groups within optdicts (see OptionsManagerMixIn.register_options_provider)

Expand Down
8 changes: 1 addition & 7 deletions pylint/config/option_manager_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,7 @@ def reset_parsers(self, usage=""):

def register_options_provider(self, provider, own_group=True):
"""Register an options provider."""
assert provider.priority <= 0, "provider's priority can't be >= 0"
for i, options_provider in enumerate(self.options_providers):
if provider.priority > options_provider.priority:
self.options_providers.insert(i, provider)
break
else:
self.options_providers.append(provider)
self.options_providers.append(provider)
non_group_spec_options = [
option for option in provider.options if "group" not in option[1]
]
Expand Down
1 change: 0 additions & 1 deletion pylint/config/options_provider_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class OptionsProviderMixIn:
"""Mixin to provide options to an OptionsManager."""

# those attributes should be overridden
priority = -1
name = "default"
options: Tuple[Tuple[str, Dict[str, Any]], ...] = ()
level = 0
Expand Down
1 change: 0 additions & 1 deletion pylint/extensions/broad_try_clause.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class BroadTryClauseChecker(checkers.BaseChecker):
)
}

priority = -2
options = (
(
"max-try-statements",
Expand Down
1 change: 0 additions & 1 deletion pylint/extensions/code_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class CodeStyleChecker(BaseChecker):
__implements__ = (IAstroidChecker,)

name = "code_style"
priority = -1
msgs = {
"R6101": (
"Consider using namedtuple or dataclass for dictionary values",
Expand Down
1 change: 0 additions & 1 deletion pylint/extensions/comparetozero.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class CompareToZeroChecker(checkers.BaseChecker):
)
}

priority = -2
options = ()

@utils.check_messages("compare-to-zero")
Expand Down
1 change: 0 additions & 1 deletion pylint/extensions/confusing_elif.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class ConfusingConsecutiveElifChecker(BaseChecker):
__implements__ = IAstroidChecker

name = "confusing_elif"
priority = -1
msgs = {
"R5601": (
"Consecutive elif with differing indentation level, consider creating a function to separate the inner elif",
Expand Down
2 changes: 0 additions & 2 deletions pylint/extensions/docparams.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,6 @@ class DocstringParameterChecker(BaseChecker):
),
)

priority = -2

constructor_names = {"__init__", "__new__"}
not_needed_param_in_docstring = {"self", "cls"}

Expand Down
1 change: 0 additions & 1 deletion pylint/extensions/empty_comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ class CommentChecker(BaseChecker):
)
}
options = ()
priority = -1 # low priority

def process_module(self, node: nodes.Module) -> None:
with node.stream() as stream:
Expand Down
1 change: 0 additions & 1 deletion pylint/extensions/emptystring.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class CompareToEmptyStringChecker(checkers.BaseChecker):
)
}

priority = -2
options = ()

@utils.check_messages("compare-to-empty-string")
Expand Down
1 change: 0 additions & 1 deletion pylint/extensions/overlapping_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class OverlappingExceptionsChecker(checkers.BaseChecker):
"Used when exceptions in handler overlap or are identical",
)
}
priority = -2
options = ()

@utils.check_messages("overlapping-except")
Expand Down
1 change: 0 additions & 1 deletion pylint/extensions/set_membership.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class SetMembershipChecker(BaseChecker):
__implements__ = (IAstroidChecker,)

name = "set_membership"
priority = -1
msgs = {
"R6201": (
"Consider using set for membership test",
Expand Down
1 change: 0 additions & 1 deletion pylint/extensions/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ class TypingChecker(BaseChecker):
__implements__ = (IAstroidChecker,)

name = "typing"
priority = -1
msgs = {
"W6001": (
"'%s' is deprecated, use '%s' instead",
Expand Down
7 changes: 0 additions & 7 deletions pylint/lint/pylinter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import collections
import contextlib
import functools
import operator
import os
import sys
import tokenize
Expand Down Expand Up @@ -214,7 +213,6 @@ class PyLinter(
__implements__ = (interfaces.ITokenChecker,)

name = MAIN_CHECKER_NAME
priority = 0
level = 0
msgs = MSGS
# Will be used like this : datetime.now().strftime(crash_file_path)
Expand Down Expand Up @@ -764,7 +762,6 @@ def report_order(self):

def register_checker(self, checker: checkers.BaseChecker) -> None:
"""This method auto registers the checker."""
assert checker.priority <= 0, "checker priority can't be >= 0"
self._checkers[checker.name].append(checker)
for r_id, r_title, r_cb in checker.reports:
self.register_report(r_id, r_title, r_cb, checker)
Expand Down Expand Up @@ -973,10 +970,6 @@ def prepare_checkers(self):
messages = {msg for msg in checker.msgs if self.is_message_enabled(msg)}
if messages or any(self.report_is_enabled(r[0]) for r in checker.reports):
needed_checkers.append(checker)
# Sort checkers by priority
needed_checkers = sorted(
needed_checkers, key=operator.attrgetter("priority"), reverse=True
)
return needed_checkers

# pylint: disable=unused-argument
Expand Down

0 comments on commit e01fa86

Please sign in to comment.