|
1 | 1 | """Augmentations."""
|
2 | 2 | # pylint: disable=invalid-name
|
| 3 | +import itertools |
| 4 | + |
3 | 5 | from astroid import InferenceError
|
4 | 6 | from astroid.objects import Super
|
5 | 7 | from astroid.nodes import ClassDef, ImportFrom, Attribute
|
|
22 | 24 | from django.views.generic.detail import SingleObjectMixin, SingleObjectTemplateResponseMixin, TemplateResponseMixin
|
23 | 25 | from django.views.generic.edit import DeletionMixin, FormMixin, ModelFormMixin
|
24 | 26 | from django.views.generic.list import MultipleObjectMixin, MultipleObjectTemplateResponseMixin
|
| 27 | +from django.utils import termcolors |
25 | 28 |
|
26 | 29 | from pylint_django.utils import node_is_subclass, PY3
|
27 | 30 |
|
|
258 | 261 | }
|
259 | 262 |
|
260 | 263 |
|
| 264 | +STYLE_ATTRS = set(itertools.chain.from_iterable(termcolors.PALETTES.values())) |
| 265 | + |
| 266 | + |
261 | 267 | VIEW_ATTRS = {
|
262 | 268 | (
|
263 | 269 | (
|
@@ -472,6 +478,11 @@ def _attribute_is_magic(node, attrs, parents):
|
472 | 478 | return False
|
473 | 479 |
|
474 | 480 |
|
| 481 | +def is_style_attribute(node): |
| 482 | + parents = ('django.core.management.color.Style', ) |
| 483 | + return _attribute_is_magic(node, STYLE_ATTRS, parents) |
| 484 | + |
| 485 | + |
475 | 486 | def is_manager_attribute(node):
|
476 | 487 | """Checks that node is attribute of Manager or QuerySet class."""
|
477 | 488 | parents = ('django.db.models.manager.Manager',
|
@@ -757,6 +768,7 @@ def apply_augmentations(linter):
|
757 | 768 | augment_visit(linter, _visit_attribute(TypeChecker), foreign_key_sets)
|
758 | 769 | augment_visit(linter, _visit_attribute(TypeChecker), foreign_key_ids)
|
759 | 770 | suppress_message(linter, _visit_attribute(TypeChecker), 'no-member', is_model_field_display_method)
|
| 771 | + suppress_message(linter, _visit_attribute(TypeChecker), 'no-member', is_style_attribute) |
760 | 772 |
|
761 | 773 | # supress errors when accessing magical class attributes
|
762 | 774 | suppress_message(linter, _visit_attribute(TypeChecker), 'no-member', is_manager_attribute)
|
|
0 commit comments