Skip to content

Commit ee3704f

Browse files
Drop python 2 support using the PY3 checks
1 parent a736bd1 commit ee3704f

File tree

6 files changed

+19
-37
lines changed

6 files changed

+19
-37
lines changed

CHANGELOG.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ Other
1111
- CI now tests against Django 5.2
1212
- CI now tests against python 3.13
1313
- CI now tests against python 3.14
14+
- model-missing-unicode (W5101) could not be emitted anymore as it was related
15+
to python 2 and it was removed.
1416

1517

1618
Version 2.6.1

pylint_django/__pkginfo__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""pkginfo."""
22

3-
BASE_ID = 51
3+
BASE_ID = 51 # Identifier for pylint-django messages

pylint_django/augmentations/__init__.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from pylint.checkers.variables import ScopeConsumer, VariablesChecker
2525
from pylint_plugin_utils import augment_visit, suppress_message
2626

27-
from pylint_django.utils import PY3, node_is_subclass
27+
from pylint_django.utils import node_is_subclass
2828

2929
# Note: it would have been nice to import the Manager object from Django and
3030
# get its attributes that way - and this used to be the method - but unfortunately
@@ -317,7 +317,7 @@ def ignore_import_warnings_for_related_fields(orig_method, self, node):
317317

318318
new_things = {}
319319

320-
iterat = consumer.to_consume.items if PY3 else consumer.to_consume.iteritems
320+
iterat = consumer.to_consume.items
321321
for name, stmts in iterat():
322322
if isinstance(stmts[0], ImportFrom):
323323
if any(n[0] in ("ForeignKey", "OneToOneField") for n in stmts[0].names):
@@ -363,7 +363,7 @@ class ModelB(models.Model):
363363
quack = False
364364

365365
if node.attrname in MANAGER_ATTRS or node.attrname.endswith("_set"):
366-
# if this is a X_set method, that's a pretty strong signal that this is the default
366+
# if this is an X_set method, that's a pretty strong signal that this is the default
367367
# Django name, rather than one set by related_name
368368
quack = True
369369
# we will
@@ -651,7 +651,7 @@ def __call__(self, node):
651651

652652

653653
def is_model_view_subclass_method_shouldnt_be_function(node):
654-
"""Checks that node is a default http method (i.e get, post, put, and more) of the View class."""
654+
"""Checks that node is a default http method (i.e. get, post, put, and more) of the View class."""
655655
if node.name not in View.http_method_names:
656656
return False
657657

@@ -672,8 +672,9 @@ def ignore_unused_argument_warnings_for_request(orig_method, self, stmt, name):
672672
"""
673673
Ignore unused-argument warnings for function arguments named "request".
674674
675-
The signature of Django view functions require the request argument but it is okay if the request is not used.
676-
This function should be used as a wrapper for the `VariablesChecker._is_name_ignored` method.
675+
The signature of Django view functions require the request argument, but
676+
it is okay if the request is not used. This function should be used as a
677+
wrapper for the `VariablesChecker._is_name_ignored` method.
677678
"""
678679
if name in ("request", "args", "kwargs"):
679680
return True

pylint_django/checkers/models.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,14 @@
55
from pylint.checkers.utils import only_required_for_messages
66

77
from pylint_django.__pkginfo__ import BASE_ID
8-
from pylint_django.utils import PY3, node_is_subclass
8+
from pylint_django.utils import node_is_subclass
99

1010
MESSAGES = {
1111
f"E{BASE_ID}01": (
1212
"__unicode__ on a model must be callable (%s)",
1313
"model-unicode-not-callable",
1414
"Django models require a callable __unicode__ method",
1515
),
16-
f"W{BASE_ID}01": (
17-
"No __unicode__ method on model (%s)",
18-
"model-missing-unicode",
19-
"Django models should implement a __unicode__ method for string representation",
20-
),
2116
f"W{BASE_ID}02": (
2217
"Found __unicode__ method on model (%s). Python3 uses __str__.",
2318
"model-has-unicode",
@@ -108,9 +103,7 @@ def visit_classdef(self, node): # noqa: PLR0911
108103
return
109104

110105
if isinstance(child, FunctionDef) and child.name == "__unicode__":
111-
if PY3:
112-
self.add_message(f"W{BASE_ID}02", args=node.name, node=node)
113-
return
106+
self.add_message(f"W{BASE_ID}02", args=node.name, node=node)
114107

115108
# if we get here, then we have no __unicode__ method directly on the class itself
116109

@@ -126,8 +119,4 @@ def visit_classdef(self, node): # noqa: PLR0911
126119
# see https://github.com/pylint-dev/pylint-django/issues/10
127120
if _has_python_2_unicode_compatible_decorator(node):
128121
return
129-
130-
if PY3:
131-
return
132-
133-
self.add_message(f"W{BASE_ID}01", args=node.name, node=node)
122+
return

pylint_django/transforms/fields.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from astroid import MANAGER, AstroidImportError, inference_tip, nodes
22
from astroid.nodes import scoped_nodes
33

4-
from pylint_django import compat, utils
4+
from pylint_django import compat
55

66
_STR_FIELDS = (
77
"CharField",
@@ -97,17 +97,11 @@ def apply_type_shim(cls, _context=None): # pylint: disable=too-many-statements
9797
base_nodes = MANAGER.ast_from_module_name("psycopg2._range").lookup("Range")
9898
else:
9999
return iter([cls])
100-
101-
# XXX: for some reason, with python3, this particular line triggers a
102-
# check in the StdlibChecker for deprecated methods; one of these nodes
103-
# is an ImportFrom which has no qname() method, causing the checker
104-
# to die...
105-
if utils.PY3:
106-
base_nodes = [_valid_base_node(n, _context) for n in base_nodes[1]]
107-
base_nodes = [n for n in base_nodes if n]
108-
else:
109-
base_nodes = list(base_nodes[1])
110-
100+
# For some reason, this particular line triggers a check in the
101+
# StdlibChecker for deprecated methods; one of these nodes is an
102+
# ImportFrom which has no qname() method, causing the checker to die...
103+
base_nodes = [_valid_base_node(n, _context) for n in base_nodes[1]]
104+
base_nodes = [n for n in base_nodes if n]
111105
return iter([cls, *base_nodes])
112106

113107

pylint_django/utils.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
"""Utils."""
22

3-
import sys
4-
53
import astroid
64
from astroid import Uninferable
75
from astroid.bases import Instance
86
from astroid.exceptions import InferenceError
97
from astroid.nodes import ClassDef
108

11-
PY3 = sys.version_info >= (3, 0) # TODO: pylint_django doesn't support Py2 any more
12-
139

1410
def node_is_subclass(cls, *subclass_names):
1511
"""Checks if cls node has parent with subclass_name."""

0 commit comments

Comments
 (0)