Skip to content

Commit 417f7cf

Browse files
committed
[#358] Fix ScopeConsumer use depending on pylint version
1 parent 0beda64 commit 417f7cf

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

CHANGELOG.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
Changelog
22
=========
33

4+
Version 2.5.3 (25 Mär 2022)
5+
---------------------------
6+
7+
Bugfixes
8+
~~~~~~~~
9+
10+
- Fixed compatibility issue between pylint `2.12` and `2.13` to construct `ScopeConsumer` tuples correctly depending on version (`#358 <https://github.com/PyCQA/pylint-django/issues/358>`_)
11+
12+
Other
13+
~~~~~
14+
15+
- pylint version is now pinned to `<3` to give breathing space to update pylint-django before the major update lands
16+
417
Version 2.5.2 (18 Feb 2022)
518
---------------------------
619

pylint_django/augmentations/__init__.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
from pylint.checkers.variables import ScopeConsumer, VariablesChecker
3737
from pylint_plugin_utils import augment_visit, suppress_message
3838

39-
from pylint_django.utils import PY3, node_is_subclass
39+
from pylint_django.utils import node_is_subclass
4040

4141
# Note: it would have been nice to import the Manager object from Django and
4242
# get its attributes that way - and this used to be the method - but unfortunately
@@ -329,14 +329,22 @@ def ignore_import_warnings_for_related_fields(orig_method, self, node):
329329

330330
new_things = {}
331331

332-
iterat = consumer.to_consume.items if PY3 else consumer.to_consume.iteritems
333-
for name, stmts in iterat():
332+
for name, stmts in consumer.to_consume.items:
334333
if isinstance(stmts[0], ImportFrom):
335334
if any(n[0] in ("ForeignKey", "OneToOneField") for n in stmts[0].names):
336335
continue
337336
new_things[name] = stmts
338337

339-
consumer._atomic = ScopeConsumer(new_things, consumer.consumed, consumer.scope_type) # pylint: disable=W0212
338+
# ScopeConsumer changed between pylint 2.12 and 2.13
339+
# see https://github.com/PyCQA/pylint/issues/5970#issuecomment-1078778393
340+
if hasattr(consumer, "consumed_uncertain"):
341+
# this is pylint >= 2.13, and the ScopeConsumer tuple has an additional field
342+
sc_args = (new_things, consumer.consumed, consumer.consumed_uncertain, consumer.scope_type)
343+
else:
344+
# this is <2.13 and does not have the consumer_uncertain field
345+
sc_args = (new_things, consumer.consumed, consumer.scope_type)
346+
347+
consumer._atomic = ScopeConsumer(*sc_args) # pylint: disable=W0212
340348
self._to_consume = [consumer] # pylint: disable=W0212
341349

342350
return orig_method(self, node)

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
author_email="[email protected]",
1515
description="A Pylint plugin to help Pylint understand the Django web framework",
1616
long_description=LONG_DESCRIPTION,
17-
version="2.5.2",
17+
version="2.5.3",
1818
packages=find_packages(),
1919
include_package_data=True,
2020
install_requires=[
2121
"pylint-plugin-utils>=0.7",
22-
"pylint>=2.0",
22+
"pylint>=2.0,<3",
2323
],
2424
extras_require={
2525
"with_django": ["Django"],

0 commit comments

Comments
 (0)