Skip to content

Commit 3b760ed

Browse files
Matej Spiller Muyscarlio
Matej Spiller Muys
authored andcommitted
Support for pylint 3.x
1 parent 86bf375 commit 3b760ed

File tree

10 files changed

+28
-35
lines changed

10 files changed

+28
-35
lines changed

pylint_django/checkers/auth_user.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
from pylint import checkers, interfaces
2-
from pylint.checkers import utils
1+
from pylint import checkers
32

43
from pylint_django.__pkginfo__ import BASE_ID
4+
from pylint_django.compat import check_messages
55

66

77
class AuthUserChecker(checkers.BaseChecker):
8-
__implements__ = (interfaces.IAstroidChecker,)
9-
108
name = "auth-user-checker"
119

1210
msgs = {
@@ -22,14 +20,14 @@ class AuthUserChecker(checkers.BaseChecker):
2220
),
2321
}
2422

25-
@utils.check_messages("hard-coded-auth-user")
23+
@check_messages("hard-coded-auth-user")
2624
def visit_const(self, node):
2725
# for now we don't check if the parent is a ForeignKey field
2826
# because the user model should not be hard-coded anywhere
2927
if node.value == "auth.User":
3028
self.add_message("hard-coded-auth-user", node=node)
3129

32-
@utils.check_messages("imported-auth-user")
30+
@check_messages("imported-auth-user")
3331
def visit_importfrom(self, node):
3432
if node.modname == "django.contrib.auth.models":
3533
for imported_names in node.names:

pylint_django/checkers/django_installed.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from __future__ import absolute_import
22

33
from pylint.checkers import BaseChecker
4-
from pylint.checkers.utils import check_messages
54

65
from pylint_django.__pkginfo__ import BASE_ID
6+
from pylint_django.compat import check_messages
77

88

99
class DjangoInstalledChecker(BaseChecker):

pylint_django/checkers/foreign_key_strings.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22

33
import astroid
44
from pylint.checkers import BaseChecker
5-
from pylint.checkers.utils import check_messages
6-
from pylint.interfaces import IAstroidChecker
75

86
from pylint_django.__pkginfo__ import BASE_ID
7+
from pylint_django.compat import check_messages
98
from pylint_django.transforms import foreignkey
109

1110

@@ -27,8 +26,6 @@ class ForeignKeyStringsChecker(BaseChecker):
2726
Some basic default settings were used, however this will lead to less accurate linting.
2827
Consider passing in an explicit Django configuration file to match your project to improve accuracy."""
2928

30-
__implements__ = (IAstroidChecker,)
31-
3229
name = "Django foreign keys referenced by strings"
3330

3431
options = (
@@ -95,7 +92,12 @@ def open(self):
9592
# this means that Django wasn't able to configure itself using some defaults
9693
# provided (likely in a DJANGO_SETTINGS_MODULE environment variable)
9794
# so see if the user has specified a pylint option
98-
if self.config.django_settings_module is None:
95+
if hasattr(self, "linter"):
96+
django_settings_module = self.linter.config.django_settings_module
97+
else:
98+
django_settings_module = self.config.django_settings_module
99+
100+
if django_settings_module is None:
99101
# we will warn the user that they haven't actually configured Django themselves
100102
self._raise_warning = True
101103
# but use django defaults then...
@@ -108,7 +110,7 @@ def open(self):
108110
try:
109111
from django.conf import Settings, settings # pylint: disable=import-outside-toplevel
110112

111-
settings.configure(Settings(self.config.django_settings_module))
113+
settings.configure(Settings(django_settings_module))
112114
django.setup()
113115
except ImportError:
114116
# we could not find the provided settings module...

pylint_django/checkers/forms.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
"""Models."""
22
from astroid.nodes import Assign, AssignName, ClassDef
33
from pylint.checkers import BaseChecker
4-
from pylint.checkers.utils import check_messages
5-
from pylint.interfaces import IAstroidChecker
64

75
from pylint_django.__pkginfo__ import BASE_ID
6+
from pylint_django.compat import check_messages
87
from pylint_django.utils import node_is_subclass
98

109

@@ -18,8 +17,6 @@ def _get_child_meta(node):
1817
class FormChecker(BaseChecker):
1918
"""Django model checker."""
2019

21-
__implements__ = IAstroidChecker
22-
2320
name = "django-form-checker"
2421
msgs = {
2522
f"W{BASE_ID}04": (

pylint_django/checkers/json_response.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
"""
88

99
import astroid
10-
from pylint import checkers, interfaces
11-
from pylint.checkers import utils
10+
from pylint import checkers
1211

1312
from pylint_django.__pkginfo__ import BASE_ID
13+
from pylint_django.compat import check_messages
1414

1515

1616
class JsonResponseChecker(checkers.BaseChecker):
@@ -19,8 +19,6 @@ class JsonResponseChecker(checkers.BaseChecker):
1919
JSON data!
2020
"""
2121

22-
__implements__ = (interfaces.IAstroidChecker,)
23-
2422
# configuration section name
2523
name = "json-response-checker"
2624
msgs = {
@@ -43,7 +41,7 @@ class JsonResponseChecker(checkers.BaseChecker):
4341
),
4442
}
4543

46-
@utils.check_messages(
44+
@check_messages(
4745
"http-response-with-json-dumps",
4846
"http-response-with-content-type-json",
4947
"redundant-content-type-for-json-response",

pylint_django/checkers/migrations.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010

1111
import astroid
1212
from pylint import checkers, interfaces
13-
from pylint.checkers import utils
1413
from pylint_plugin_utils import suppress_message
1514

1615
from pylint_django import compat
1716
from pylint_django.__pkginfo__ import BASE_ID
17+
from pylint_django.compat import check_messages
1818
from pylint_django.utils import is_migrations_module
1919

2020

@@ -86,7 +86,7 @@ def visit_call(self, node):
8686
if node not in self._possible_offences[module]:
8787
self._possible_offences[module].append(node)
8888

89-
@utils.check_messages("new-db-field-with-default")
89+
@check_messages("new-db-field-with-default")
9090
def close(self):
9191
def _path(node):
9292
return node.path
@@ -125,7 +125,7 @@ class MissingBackwardsMigrationChecker(checkers.BaseChecker):
125125
)
126126
}
127127

128-
@utils.check_messages("missing-backwards-migration-callable")
128+
@check_messages("missing-backwards-migration-callable")
129129
def visit_call(self, node):
130130
try:
131131
module = node.frame().parent

pylint_django/checkers/models.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
from astroid import Const
33
from astroid.nodes import Assign, AssignName, ClassDef, FunctionDef
44
from pylint.checkers import BaseChecker
5-
from pylint.checkers.utils import check_messages
6-
from pylint.interfaces import IAstroidChecker
75

86
from pylint_django.__pkginfo__ import BASE_ID
7+
from pylint_django.compat import check_messages
98
from pylint_django.utils import PY3, node_is_subclass
109

1110
MESSAGES = {
@@ -75,8 +74,6 @@ def _is_unicode_or_str_in_python_2_compatibility(method):
7574
class ModelChecker(BaseChecker):
7675
"""Django model checker."""
7776

78-
__implements__ = IAstroidChecker
79-
8077
name = "django-model-checker"
8178
msgs = MESSAGES
8279

pylint_django/compat.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
except ImportError:
2121
from astroid.util import Uninferable
2222

23+
try:
24+
from pylint.checkers.utils import check_messages
25+
except (ImportError, ModuleNotFoundError):
26+
from pylint.checkers.utils import only_required_for_messages as check_messages
27+
2328
import pylint
2429

2530
# pylint before version 2.3 does not support load_configuration() hook.

pylint_django/plugin.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
"""Common Django module."""
2-
from pylint.checkers.base import NameChecker
3-
from pylint_plugin_utils import get_checker
4-
52
# we want to import the transforms to make sure they get added to the astroid manager,
63
# however we don't actually access them directly, so we'll disable the warning
74
from pylint_django import transforms # noqa, pylint: disable=unused-import
@@ -13,8 +10,7 @@ def load_configuration(linter):
1310
"""
1411
Amend existing checker config.
1512
"""
16-
name_checker = get_checker(linter, NameChecker)
17-
name_checker.config.good_names += (
13+
linter.config.good_names += (
1814
"pk",
1915
"qs",
2016
"urlpatterns",

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ exclude = ["**/tests/**", "**/testutils.py", "**/tests.py"]
4242
[tool.poetry.dependencies]
4343
python = ">=3.7,<4.0"
4444
pylint-plugin-utils = ">=0.8"
45-
pylint = ">=2.0,<3"
45+
pylint = ">=2.0,<4"
4646
Django = {version=">=2.2", optional = true}
4747

4848
[tool.poetry.group.dev.dependencies]

0 commit comments

Comments
 (0)