Skip to content

Commit

Permalink
Pylint 3.0.2 support (#371)
Browse files Browse the repository at this point in the history
feat: upgrade pylint to 3.0
  • Loading branch information
irtazaakram authored Oct 24, 2023
1 parent f7762f5 commit deaf339
Show file tree
Hide file tree
Showing 19 changed files with 64 additions and 114 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ Change Log
Unreleased
~~~~~~~~~~

5.3.5 - 2023-04-29
~~~~~~~~~~~~~~~~~~

* added support for pylint 3

5.3.2 - 2023-02-15
~~~~~~~~~~~~~~~~~~

Expand Down
2 changes: 1 addition & 1 deletion edx_lint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
edx_lint standardizes lint configuration and additional plugins for use in
Open edX code.
"""
__version__ = "5.3.4"
__version__ = "5.3.5"
24 changes: 8 additions & 16 deletions edx_lint/pylint/annotations_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@

import pkg_resources

from astroid.node_classes import Const, Name
from astroid.nodes.node_classes import Const, Name
from code_annotations import annotation_errors
from code_annotations.base import AnnotationConfig
from code_annotations.find_static import StaticSearch
from pylint.checkers import BaseChecker, utils
from pylint.interfaces import IAstroidChecker

from .common import BASE_ID, check_visitors

Expand All @@ -31,7 +30,7 @@ def check_all_messages(msgs):
"""
Decorator to automatically assign all messages from a class to the list of messages handled by a checker method.
Inspired by pylint.checkers.util.check_messages
Inspired by pylint.checkers.util.only_required_for_messages
"""

def store_messages(func):
Expand Down Expand Up @@ -94,8 +93,6 @@ class FeatureToggleChecker(BaseChecker):
are followed.
"""

__implements__ = (IAstroidChecker,)

name = "feature-toggle-checker"

TOGGLE_NOT_ANNOTATED_MESSAGE_ID = "feature-toggle-needs-doc"
Expand Down Expand Up @@ -218,23 +215,23 @@ def check_illegal_waffle_usage(self, node):
self.ILLEGAL_WAFFLE_MESSAGE_ID, args=(feature_toggle_name,), node=node
)

@utils.check_messages(TOGGLE_NOT_ANNOTATED_MESSAGE_ID, ILLEGAL_WAFFLE_MESSAGE_ID)
@utils.only_required_for_messages(TOGGLE_NOT_ANNOTATED_MESSAGE_ID, ILLEGAL_WAFFLE_MESSAGE_ID)
def visit_call(self, node):
"""
Performs various checks on Call nodes.
"""
self.check_waffle_class_annotated(node)
self.check_illegal_waffle_usage(node)

@utils.check_messages(TOGGLE_NOT_ANNOTATED_MESSAGE_ID)
@utils.only_required_for_messages(TOGGLE_NOT_ANNOTATED_MESSAGE_ID)
def visit_classdef(self, node):
"""
Checks class definitions for potential ConfigurationModel
implementations.
"""
self.check_configuration_model_annotated(node)

@utils.check_messages(TOGGLE_NOT_ANNOTATED_MESSAGE_ID)
@utils.only_required_for_messages(TOGGLE_NOT_ANNOTATED_MESSAGE_ID)
def visit_dict(self, node):
"""
Checks Dict nodes in case a Django FEATURES dictionary is being
Expand Down Expand Up @@ -301,7 +298,6 @@ class CodeAnnotationChecker(AnnotationBaseChecker):
CodeAnnotationChecker.CONFIG_FILENAMES (see AnnotationBaseChecker docs).
"""
CONFIG_FILENAMES = ["feature_toggle_annotations.yaml", "setting_annotations.yaml"]
__implements__ = (IAstroidChecker,)
name = "code-annotations"
msgs = {
("E%d%d" % (BASE_ID, index + 50)): (
Expand Down Expand Up @@ -338,8 +334,6 @@ class FeatureToggleAnnotationChecker(AnnotationBaseChecker):

CONFIG_FILENAMES = ["feature_toggle_annotations.yaml"]

__implements__ = (IAstroidChecker,)

name = "toggle-annotations"

NO_NAME_MESSAGE_ID = "toggle-no-name"
Expand Down Expand Up @@ -471,7 +465,7 @@ def check_annotation_group(self, search, annotations, node):
line=line_number,
)

@utils.check_messages(MISSING_ANNOTATION)
@utils.only_required_for_messages(MISSING_ANNOTATION)
def visit_call(self, node):
"""
Check for missing annotations.
Expand All @@ -482,15 +476,15 @@ def visit_call(self, node):
node=node,
)

@utils.check_messages(INVALID_DJANGO_WAFFLE_IMPORT)
@utils.only_required_for_messages(INVALID_DJANGO_WAFFLE_IMPORT)
def visit_import(self, node):
if node.names[0][0] == "waffle":
self.add_message(
self.INVALID_DJANGO_WAFFLE_IMPORT,
node=node,
)

@utils.check_messages(INVALID_DJANGO_WAFFLE_IMPORT)
@utils.only_required_for_messages(INVALID_DJANGO_WAFFLE_IMPORT)
def visit_importfrom(self, node):
if node.modname == "waffle":
self.add_message(
Expand Down Expand Up @@ -533,8 +527,6 @@ class SettingAnnotationChecker(AnnotationBaseChecker):

CONFIG_FILENAMES = ["setting_annotations.yaml"]

__implements__ = (IAstroidChecker,)

name = "setting-annotations"

BOOLEAN_DEFAULT_VALUE = "setting-boolean-default-value"
Expand Down
6 changes: 1 addition & 5 deletions edx_lint/pylint/getattr_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import astroid
from pylint.checkers import BaseChecker, utils
from pylint.interfaces import IAstroidChecker

from .common import BASE_ID, check_visitors

Expand Down Expand Up @@ -38,9 +37,6 @@ class GetSetAttrLiteralChecker(BaseChecker):
The message id is literal-used-as-attribute.
"""

__implements__ = (IAstroidChecker,)

name = "getattr-literal-checker"

MESSAGE_ID = "literal-used-as-attribute"
Expand All @@ -52,7 +48,7 @@ class GetSetAttrLiteralChecker(BaseChecker):
)
}

@utils.check_messages(MESSAGE_ID)
@utils.only_required_for_messages(MESSAGE_ID)
def visit_call(self, node):
"""Called for every function call in the source code."""
if not isinstance(node.func, astroid.Name):
Expand Down
5 changes: 1 addition & 4 deletions edx_lint/pylint/i18n_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import astroid
from pylint.checkers import BaseChecker, utils
from pylint.interfaces import IAstroidChecker

from .common import BASE_ID, check_visitors

Expand Down Expand Up @@ -30,8 +29,6 @@ class TranslationStringConstantsChecker(BaseChecker):
"""

__implements__ = (IAstroidChecker,)

name = "translation-string-checker"

TRANSLATION_FUNCTIONS = {
Expand Down Expand Up @@ -59,7 +56,7 @@ class TranslationStringConstantsChecker(BaseChecker):
)
}

@utils.check_messages(MESSAGE_ID)
@utils.only_required_for_messages(MESSAGE_ID)
def visit_call(self, node):
"""Called for every function call in the source code."""
if not isinstance(node.func, astroid.Name):
Expand Down
5 changes: 1 addition & 4 deletions edx_lint/pylint/layered_test_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import astroid

from pylint.checkers import BaseChecker, utils
from pylint.interfaces import IAstroidChecker

from .common import BASE_ID, check_visitors

Expand Down Expand Up @@ -37,8 +36,6 @@ def is_test_case_class(node):
class LayeredTestClassChecker(BaseChecker):
"""Pylint checker for tests inheriting test methods from other tests."""

__implements__ = (IAstroidChecker,)

name = "layered-test-class-checker"

MESSAGE_ID = "test-inherits-tests"
Expand All @@ -51,7 +48,7 @@ class LayeredTestClassChecker(BaseChecker):
)
}

@utils.check_messages(MESSAGE_ID)
@utils.only_required_for_messages(MESSAGE_ID)
def visit_classdef(self, node):
"""Check each class."""
if not is_test_case_class(node):
Expand Down
3 changes: 0 additions & 3 deletions edx_lint/pylint/module_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import os

from pylint.checkers import BaseChecker
from pylint.interfaces import IAstroidChecker

from .common import BASE_ID, check_visitors

Expand All @@ -33,8 +32,6 @@ class ModuleTracingChecker(BaseChecker):
a better way to hook into pylint to do this.
"""

__implements__ = (IAstroidChecker,)

name = "module-tracing-checker"

msgs = {("E%d00" % BASE_ID): ("bogus", "bogus", "bogus")}
Expand Down
5 changes: 1 addition & 4 deletions edx_lint/pylint/range_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import astroid

from pylint.checkers import BaseChecker, utils
from pylint.interfaces import IAstroidChecker

from .common import BASE_ID, check_visitors

Expand Down Expand Up @@ -31,16 +30,14 @@ class RangeChecker(BaseChecker):
"""

__implements__ = (IAstroidChecker,)

name = "range-checker"

RANGE_FUNCTIONS = ["range", "xrange"]

MESSAGE_ID = "simplifiable-range"
msgs = {("C%d20" % BASE_ID): ("%s() call could be %s-argument", MESSAGE_ID, "range() call could be simplified")}

@utils.check_messages(MESSAGE_ID)
@utils.only_required_for_messages(MESSAGE_ID)
def visit_call(self, node):
"""Called for every function call in the source code."""
if not isinstance(node.func, astroid.Name):
Expand Down
5 changes: 1 addition & 4 deletions edx_lint/pylint/right_assert_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"""
import astroid

from pylint.interfaces import IAstroidChecker
from pylint.checkers import BaseChecker, utils

from .common import BASE_ID, check_visitors
Expand All @@ -23,8 +22,6 @@ class AssertChecker(BaseChecker):
assert is used if assertTrue or assertFalse are misused.
"""

__implements__ = (IAstroidChecker,)

name = "assert-checker"

AFFECTED_ASSERTS = ["assertTrue", "assertFalse"]
Expand Down Expand Up @@ -66,7 +63,7 @@ class AssertChecker(BaseChecker):
MESSAGE_ID = "wrong-assert-type"
msgs = {("C%d90" % BASE_ID): ("%s", MESSAGE_ID, "Use assert(Not)Equal instead of assertTrue/False")}

@utils.check_messages(MESSAGE_ID)
@utils.only_required_for_messages(MESSAGE_ID)
def visit_call(self, node):
"""
Check that various assertTrue/False functions are not misused.
Expand Down
5 changes: 1 addition & 4 deletions edx_lint/pylint/super_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from pylint.checkers.classes import _ancestors_to_call
except ImportError: # Backward compatibility with pylint<2.13
from pylint.checkers.classes.class_checker import _ancestors_to_call
from pylint.interfaces import IAstroidChecker

from .common import BASE_ID, check_visitors, usable_class_name

Expand All @@ -28,8 +27,6 @@ class name, it issues a `non-parent-method-called` error.
"""

__implements__ = (IAstroidChecker,)

name = "unit-test-super-checker"

NOT_CALLED_MESSAGE_ID = "super-method-not-called"
Expand All @@ -50,7 +47,7 @@ class name, it issues a `non-parent-method-called` error.
),
}

@utils.check_messages(NOT_CALLED_MESSAGE_ID, NON_PARENT_MESSAGE_ID)
@utils.only_required_for_messages(NOT_CALLED_MESSAGE_ID, NON_PARENT_MESSAGE_ID)
def visit_functiondef(self, node):
"""Called for every function definition in the source code."""
# ignore actual functions
Expand Down
5 changes: 1 addition & 4 deletions edx_lint/pylint/unittest_assert/unittest_assert_check.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Checker for using pytest assertion instead of unittest assertion."""
import astroid

from pylint.interfaces import IAstroidChecker
from pylint.checkers import BaseChecker, utils

from edx_lint.pylint.common import BASE_ID, check_visitors
Expand All @@ -19,8 +18,6 @@ class UnittestAssertChecker(BaseChecker):
replace it with pytest assertions
"""

__implements__ = (IAstroidChecker,)

name = "unittest-assert-checker"

UNITTEST_ASSERTS = [
Expand Down Expand Up @@ -82,7 +79,7 @@ class UnittestAssertChecker(BaseChecker):
)
}

@utils.check_messages(MESSAGE_ID)
@utils.only_required_for_messages(MESSAGE_ID)
def visit_call(self, node):
"""
Check that unittest assertions are not used.
Expand Down
5 changes: 1 addition & 4 deletions edx_lint/pylint/yaml_load_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"""

from pylint.checkers import BaseChecker, utils
from pylint.interfaces import IAstroidChecker

from .common import BASE_ID, check_visitors

Expand All @@ -27,8 +26,6 @@ class YamlLoadChecker(BaseChecker):
Checks for unsafe ``yaml.load()`` calls.
"""

__implements__ = (IAstroidChecker,)

name = "yaml-load-checker"

MESSAGE_ID = "unsafe-yaml-load"
Expand All @@ -43,7 +40,7 @@ class YamlLoadChecker(BaseChecker):
)
}

@utils.check_messages(MESSAGE_ID)
@utils.only_required_for_messages(MESSAGE_ID)
def visit_call(self, node):
"""
Check whether a call is an unsafe call to yaml.load.
Expand Down
Loading

0 comments on commit deaf339

Please sign in to comment.