summaryrefslogtreecommitdiff
path: root/checkers/classes.py
diff options
context:
space:
mode:
authorSylvain Th?nault <sylvain.thenault@logilab.fr>2014-07-25 17:23:37 +0200
committerSylvain Th?nault <sylvain.thenault@logilab.fr>2014-07-25 17:23:37 +0200
commit94809f51eb4bc1d46e573be6763271f05558b80a (patch)
treee9b9f51e0ce1b56227b37207178cdd3f5f319f01 /checkers/classes.py
parent331732cc5019f19a323e1176b58c1d8c82c5ced4 (diff)
downloadpylint-94809f51eb4bc1d46e573be6763271f05558b80a.tar.gz
linting pylint
Diffstat (limited to 'checkers/classes.py')
-rw-r--r--checkers/classes.py80
1 files changed, 39 insertions, 41 deletions
diff --git a/checkers/classes.py b/checkers/classes.py
index 170bb19..61769f2 100644
--- a/checkers/classes.py
+++ b/checkers/classes.py
@@ -25,9 +25,9 @@ from astroid.bases import Generator
from pylint.interfaces import IAstroidChecker
from pylint.checkers import BaseChecker
-from pylint.checkers.utils import (PYMETHODS, overrides_a_method,
- check_messages, is_attr_private, is_attr_protected, node_frame_class,
- safe_infer)
+from pylint.checkers.utils import (
+ PYMETHODS, overrides_a_method, check_messages, is_attr_private,
+ is_attr_protected, node_frame_class, safe_infer)
if sys.version_info >= (3, 0):
NEXT_METHOD = '__next__'
@@ -106,12 +106,12 @@ MSGS = {
'Used when a static method has "self" or a value specified in '
'valid-classmethod-first-arg option or '
'valid-metaclass-classmethod-first-arg option as first argument.'
- ),
+ ),
'R0201': ('Method could be a function',
'no-self-use',
'Used when a method doesn\'t use its bound instance, and so could\
be written as a function.'
- ),
+ ),
'E0221': ('Interface resolved to %s is not a class',
'interface-is-not-class',
@@ -133,7 +133,7 @@ MSGS = {
'abstract-method',
'Used when an abstract method (i.e. raise NotImplementedError) is \
not overridden in concrete class.'
- ),
+ ),
'F0220': ('failed to resolve interfaces implemented by %s (%s)', # W0224
'unresolved-interface',
'Used when a PyLint as failed to find interfaces implemented by \
@@ -198,45 +198,43 @@ class ClassChecker(BaseChecker):
# configuration options
options = (('ignore-iface-methods',
{'default' : (#zope interface
- 'isImplementedBy', 'deferred', 'extends', 'names',
- 'namesAndDescriptions', 'queryDescriptionFor', 'getBases',
- 'getDescriptionFor', 'getDoc', 'getName', 'getTaggedValue',
- 'getTaggedValueTags', 'isEqualOrExtendedBy', 'setTaggedValue',
- 'isImplementedByInstancesOf',
- # twisted
- 'adaptWith',
- # logilab.common interface
- 'is_implemented_by'),
+ 'isImplementedBy', 'deferred', 'extends', 'names',
+ 'namesAndDescriptions', 'queryDescriptionFor', 'getBases',
+ 'getDescriptionFor', 'getDoc', 'getName', 'getTaggedValue',
+ 'getTaggedValueTags', 'isEqualOrExtendedBy', 'setTaggedValue',
+ 'isImplementedByInstancesOf',
+ # twisted
+ 'adaptWith',
+ # logilab.common interface
+ 'is_implemented_by'),
'type' : 'csv',
'metavar' : '<method names>',
'help' : 'List of interface methods to ignore, \
separated by a comma. This is used for instance to not check methods defines \
in Zope\'s Interface base class.'}
- ),
-
+ ),
('defining-attr-methods',
{'default' : ('__init__', '__new__', 'setUp'),
'type' : 'csv',
'metavar' : '<method names>',
'help' : 'List of method names used to declare (i.e. assign) \
instance attributes.'}
- ),
+ ),
('valid-classmethod-first-arg',
{'default' : ('cls',),
'type' : 'csv',
'metavar' : '<argument names>',
'help' : 'List of valid names for the first argument in \
a class method.'}
- ),
+ ),
('valid-metaclass-classmethod-first-arg',
{'default' : ('mcs',),
'type' : 'csv',
'metavar' : '<argument names>',
'help' : 'List of valid names for the first argument in \
a metaclass class method.'}
- ),
-
- )
+ ),
+ )
def __init__(self, linter=None):
BaseChecker.__init__(self, linter)
@@ -400,7 +398,7 @@ a metaclass class method.'}
if infered is YES:
continue
if (not isinstance(infered, astroid.Const) or
- not isinstance(infered.value, str)):
+ not isinstance(infered.value, str)):
self.add_message('invalid-slots-object',
args=infered.as_string(),
node=elt)
@@ -418,7 +416,7 @@ a metaclass class method.'}
for infered_node in infered:
if (infered_node is YES
- or isinstance(infered_node, Generator)):
+ or isinstance(infered_node, Generator)):
continue
if isinstance(infered_node, astroid.Instance):
try:
@@ -451,10 +449,10 @@ a metaclass class method.'}
return
class_node = node.parent.frame()
if (self._meth_could_be_func and node.type == 'method'
- and not node.name in PYMETHODS
- and not (node.is_abstract() or
- overrides_a_method(class_node, node.name))
- and class_node.type != 'interface'):
+ and not node.name in PYMETHODS
+ and not (node.is_abstract() or
+ overrides_a_method(class_node, node.name))
+ and class_node.type != 'interface'):
self.add_message('no-self-use', node=node)
def visit_getattr(self, node):
@@ -629,8 +627,8 @@ a metaclass class method.'}
# static method
if node.type == 'staticmethod':
if (first_arg == 'self' or
- first_arg in self.config.valid_classmethod_first_arg or
- first_arg in self.config.valid_metaclass_classmethod_first_arg):
+ first_arg in self.config.valid_classmethod_first_arg or
+ first_arg in self.config.valid_metaclass_classmethod_first_arg):
self.add_message('bad-staticmethod-argument', args=first, node=node)
return
self._first_attrs[-1] = None
@@ -641,19 +639,22 @@ a metaclass class method.'}
elif metaclass:
# metaclass __new__ or classmethod
if node.type == 'classmethod':
- self._check_first_arg_config(first,
+ self._check_first_arg_config(
+ first,
self.config.valid_metaclass_classmethod_first_arg, node,
'bad-mcs-classmethod-argument', node.name)
# metaclass regular method
else:
- self._check_first_arg_config(first,
+ self._check_first_arg_config(
+ first,
self.config.valid_classmethod_first_arg, node, 'bad-mcs-method-argument',
node.name)
# regular class
else:
# class method
if node.type == 'classmethod':
- self._check_first_arg_config(first,
+ self._check_first_arg_config(
+ first,
self.config.valid_classmethod_first_arg, node, 'bad-classmethod-argument',
node.name)
# regular method without self as argument
@@ -666,11 +667,8 @@ a metaclass class method.'}
if len(config) == 1:
valid = repr(config[0])
else:
- valid = ', '.join(
- repr(v)
- for v in config[:-1])
- valid = '%s or %r' % (
- valid, config[-1])
+ valid = ', '.join(repr(v) for v in config[:-1])
+ valid = '%s or %r' % (valid, config[-1])
self.add_message(message, args=(method_name, valid), node=node)
def _check_bases_classes(self, node):
@@ -727,7 +725,7 @@ a metaclass class method.'}
continue
# check signature
self._check_signature(method, imethod,
- '%s interface' % iface.name)
+ '%s interface' % iface.name)
except astroid.InferenceError:
if e0221_hack[0]:
return
@@ -746,7 +744,7 @@ a metaclass class method.'}
method
"""
if (not self.linter.is_message_enabled('super-init-not-called') and
- not self.linter.is_message_enabled('non-parent-init-called')):
+ not self.linter.is_message_enabled('non-parent-init-called')):
return
klass_node = node.parent.frame()
to_call = _ancestors_to_call(klass_node)
@@ -758,7 +756,7 @@ a metaclass class method.'}
continue
# skip the test if using super
if isinstance(expr.expr, astroid.CallFunc) and \
- isinstance(expr.expr.func, astroid.Name) and \
+ isinstance(expr.expr.func, astroid.Name) and \
expr.expr.func.name == 'super':
return
try: