|
36 | 36 | from pylint.checkers.variables import ScopeConsumer, VariablesChecker
|
37 | 37 | from pylint_plugin_utils import augment_visit, suppress_message
|
38 | 38 |
|
39 |
| -from pylint_django.utils import PY3, node_is_subclass |
| 39 | +from pylint_django.utils import node_is_subclass |
40 | 40 |
|
41 | 41 | # Note: it would have been nice to import the Manager object from Django and
|
42 | 42 | # 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):
|
329 | 329 |
|
330 | 330 | new_things = {}
|
331 | 331 |
|
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: |
334 | 333 | if isinstance(stmts[0], ImportFrom):
|
335 | 334 | if any(n[0] in ("ForeignKey", "OneToOneField") for n in stmts[0].names):
|
336 | 335 | continue
|
337 | 336 | new_things[name] = stmts
|
338 | 337 |
|
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 |
340 | 348 | self._to_consume = [consumer] # pylint: disable=W0212
|
341 | 349 |
|
342 | 350 | return orig_method(self, node)
|
|
0 commit comments