summaryrefslogtreecommitdiff
path: root/checkers/utils.py
diff options
context:
space:
mode:
authorSylvain Th?nault <sylvain.thenault@logilab.fr>2012-06-07 14:54:04 +0200
committerSylvain Th?nault <sylvain.thenault@logilab.fr>2012-06-07 14:54:04 +0200
commite55d63fc8e99f24395675993a520f90c4760d8d6 (patch)
treec83034480c49f8ab4a12e866ec24e32b14b19ead /checkers/utils.py
parentb38e3ef6767af52b9e85318d97bb5c15fb28505c (diff)
downloadpylint-e55d63fc8e99f24395675993a520f90c4760d8d6.tar.gz
Refactor _check_protected_attribute_access by extracting independent part in utils functions. Improve is_super_call docstring.
Diffstat (limited to 'checkers/utils.py')
-rw-r--r--checkers/utils.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/checkers/utils.py b/checkers/utils.py
index 5c8fc8e..2102bbb 100644
--- a/checkers/utils.py
+++ b/checkers/utils.py
@@ -322,6 +322,34 @@ def parse_format_string(format_string):
i += 1
return keys, num_args
+def is_attr_protected(attrname):
+ """return True if attribute name is protected (start with _ and some other
+ details), False otherwise.
+ """
+ return attrname[0] == '_' and not attrname == '_' and not (
+ attrname.startswith('__') and attrname.endswith('__'))
+
+def node_frame_class(node):
+ """return klass node for a method node (or a staticmethod or a
+ classmethod), return null otherwise
+ """
+ klass = node.frame()
+
+ while klass is not None and not isinstance(klass, astng.Class):
+ if klass.parent is None:
+ klass = None
+ else:
+ klass = klass.parent.frame()
+
+ return klass
+
+def is_super_call(expr):
+ """return True if expression node is a function call and if function name
+ is super. Check before that you're in a method.
+ """
+ return (isinstance(expr, astng.CallFunc) and
+ isinstance(expr.func, astng.Name) and
+ expr.func.name == 'super')
def is_attr_private(attrname):
"""Check that attribute name is private (at least two leading underscores,
at most one trailing underscore)