Skip to content

Commit 4f076f1

Browse files
authored
Merge pull request #159 from trbs/master
add suppression for members of Django Style class
2 parents f3f8fc7 + 6c60aa4 commit 4f076f1

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

pylint_django/augmentations/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Augmentations."""
22
# pylint: disable=invalid-name
3+
import itertools
4+
35
from astroid import InferenceError
46
from astroid.objects import Super
57
from astroid.nodes import ClassDef, ImportFrom, Attribute
@@ -22,6 +24,7 @@
2224
from django.views.generic.detail import SingleObjectMixin, SingleObjectTemplateResponseMixin, TemplateResponseMixin
2325
from django.views.generic.edit import DeletionMixin, FormMixin, ModelFormMixin
2426
from django.views.generic.list import MultipleObjectMixin, MultipleObjectTemplateResponseMixin
27+
from django.utils import termcolors
2528

2629
from pylint_django.utils import node_is_subclass, PY3
2730

@@ -258,6 +261,9 @@
258261
}
259262

260263

264+
STYLE_ATTRS = set(itertools.chain.from_iterable(termcolors.PALETTES.values()))
265+
266+
261267
VIEW_ATTRS = {
262268
(
263269
(
@@ -472,6 +478,11 @@ def _attribute_is_magic(node, attrs, parents):
472478
return False
473479

474480

481+
def is_style_attribute(node):
482+
parents = ('django.core.management.color.Style', )
483+
return _attribute_is_magic(node, STYLE_ATTRS, parents)
484+
485+
475486
def is_manager_attribute(node):
476487
"""Checks that node is attribute of Manager or QuerySet class."""
477488
parents = ('django.db.models.manager.Manager',
@@ -757,6 +768,7 @@ def apply_augmentations(linter):
757768
augment_visit(linter, _visit_attribute(TypeChecker), foreign_key_sets)
758769
augment_visit(linter, _visit_attribute(TypeChecker), foreign_key_ids)
759770
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)
760772

761773
# supress errors when accessing magical class attributes
762774
suppress_message(linter, _visit_attribute(TypeChecker), 'no-member', is_manager_attribute)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Test that using `color_style` or `no_style`
2+
# doesn't raise no-member error
3+
#
4+
# pylint: disable=missing-docstring
5+
6+
from django.core.management.color import color_style, no_style
7+
8+
9+
def function():
10+
style = color_style()
11+
print(style.SUCCESS("test"))
12+
13+
style = no_style()
14+
print(style.SUCCESS("test"))

0 commit comments

Comments
 (0)