diff options
author | Claudiu Popa <cpopa@cloudbasesolutions.com> | 2015-06-25 18:57:00 +0300 |
---|---|---|
committer | Claudiu Popa <cpopa@cloudbasesolutions.com> | 2015-06-25 18:57:00 +0300 |
commit | e8023fa85434fe2bb1989f658cfba6f3f30c3a95 (patch) | |
tree | fc40cfe66b2f3fcc71628e9b08df17ab31271166 /pylint/checkers/classes.py | |
parent | 662d019fa1125ef570be6d64c281e7d5d0f2fb25 (diff) | |
download | pylint-git-e8023fa85434fe2bb1989f658cfba6f3f30c3a95.tar.gz |
Detect a couple of objects which can't be base classes (bool, slice, range and memoryview, which weren't detected until now).
Diffstat (limited to 'pylint/checkers/classes.py')
-rw-r--r-- | pylint/checkers/classes.py | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/pylint/checkers/classes.py b/pylint/checkers/classes.py index 371db1847..962cca578 100644 --- a/pylint/checkers/classes.py +++ b/pylint/checkers/classes.py @@ -43,6 +43,7 @@ if sys.version_info >= (3, 0): else: NEXT_METHOD = 'next' ITER_METHODS = ('__iter__', '__getitem__') +INVALID_BASE_CLASSES = {'bool', 'range', 'slice', 'memoryview'} def _get_method_args(method): @@ -52,6 +53,10 @@ def _get_method_args(method): return len(args) +def _is_invalid_base_class(cls): + return cls.name in INVALID_BASE_CLASSES and is_builtin_object(cls) + + def _called_in_methods(func, klass, methods): """ Check if the func was called in any of the given methods, belonging to the *klass*. Returns True if so, False otherwise. @@ -336,7 +341,9 @@ a metaclass class method.'} if (isinstance(ancestor, astroid.Instance) and ancestor.is_subtype_of('%s.type' % (BUILTINS,))): continue - if not isinstance(ancestor, astroid.Class): + + if (not isinstance(ancestor, astroid.Class) or + _is_invalid_base_class(ancestor)): self.add_message('inherit-non-class', args=base.as_string(), node=node) |