summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--pylint/checkers/classes.py78
-rw-r--r--pylint/test/input/func_e0206.py20
-rw-r--r--pylint/test/input/func_interfaces.py112
-rw-r--r--pylint/test/messages/func_e0206.txt3
-rw-r--r--pylint/test/messages/func_interfaces.txt6
6 files changed, 9 insertions, 215 deletions
diff --git a/ChangeLog b/ChangeLog
index a42b927..80f0d61 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -86,6 +86,11 @@ ChangeLog for Pylint
* Remove interface-not-implemented warning. Closes issue #532.
+ * Remove the rest of interface checks: interface-is-not-class,
+ missing-interface-method, unresolved-interface. The reason is that
+ its better to start recommending ABCs instead of the old Zope era
+ of interfaces.
+
2015-03-14 -- 1.4.3
diff --git a/pylint/checkers/classes.py b/pylint/checkers/classes.py
index f957335..007cb42 100644
--- a/pylint/checkers/classes.py
+++ b/pylint/checkers/classes.py
@@ -171,15 +171,6 @@ MSGS = {
'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',
- 'Used when a class claims to implement an interface which is not '
- 'a class.'),
- 'E0222': ('Missing method %r from %s interface',
- 'missing-interface-method',
- 'Used when a method declared in an interface is missing from a '
- 'class implementing this interface'),
'W0221': ('Arguments number differs from %s %r method',
'arguments-differ',
'Used when a method has a different number of arguments than in '
@@ -193,12 +184,6 @@ MSGS = {
'Used when an abstract method (i.e. raise NotImplementedError) is '
'not overridden in concrete class.'
),
- 'F0220': ('failed to resolve interfaces implemented by %s (%s)',
- 'unresolved-interface',
- 'Used when a Pylint as failed to find interfaces implemented by '
- ' a class'),
-
-
'W0231': ('__init__ method from base class %r is not called',
'super-init-not-called',
'Used when an ancestor class method has an __init__ method '
@@ -253,7 +238,6 @@ class ClassChecker(BaseChecker):
* overridden methods signature
* access only to existent members via self
* attributes not defined in the __init__ method
- * supported interfaces implementation
* unreachable code
"""
@@ -321,12 +305,11 @@ a metaclass class method.'}
self._meth_could_be_func = None
def visit_class(self, node):
- """init visit variable _accessed and check interfaces
+ """init visit variable _accessed
"""
self._accessed.append(defaultdict(list))
self._check_bases_classes(node)
- self._check_interfaces(node)
- # if not an interface, exception, metaclass
+ # if not an exception or a metaclass
if node.type == 'class':
try:
node.local_attr('__init__')
@@ -558,8 +541,7 @@ a metaclass class method.'}
"""on method node, check if this method couldn't be a function
ignore class, static and abstract methods, initializer,
- methods overridden from a parent class and any
- kind of method defined in an interface for this warning
+ methods overridden from a parent class.
"""
if node.is_method():
if node.args.args is not None:
@@ -571,8 +553,7 @@ a metaclass class method.'}
and not node.name in PYMETHODS
and not (node.is_abstract() or
overrides_a_method(class_node, node.name) or
- decorated_with_property(node))
- and class_node.type != 'interface'):
+ decorated_with_property(node))):
self.add_message('no-self-use', node=node)
def visit_getattr(self, node):
@@ -843,55 +824,6 @@ a metaclass class method.'}
self.add_message('abstract-method', node=node,
args=(name, owner.name))
- def _check_interfaces(self, node):
- """check that the given class node really implements declared
- interfaces
- """
- e0221_hack = [False]
- def iface_handler(obj):
- """filter interface objects, it should be classes"""
- if not isinstance(obj, astroid.Class):
- e0221_hack[0] = True
- self.add_message('interface-is-not-class', node=node,
- args=(obj.as_string(),))
- return False
- return True
- ignore_iface_methods = self.config.ignore_iface_methods
- try:
- for iface in node.interfaces(handler_func=iface_handler):
- for imethod in iface.methods():
- name = imethod.name
- if name.startswith('_') or name in ignore_iface_methods:
- # don't check method beginning with an underscore,
- # usually belonging to the interface implementation
- continue
- # get class method astroid
- try:
- method = node_method(node, name)
- except astroid.NotFoundError:
- self.add_message('missing-interface-method',
- args=(name, iface.name),
- node=node)
- continue
- # ignore inherited methods
- if method.parent.frame() is not node:
- continue
- # check signature
- self._check_signature(method, imethod,
- '%s interface' % iface.name)
- except astroid.InferenceError:
- if e0221_hack[0]:
- return
- implements = Instance(node).getattr('__implements__')[0]
- assignment = implements.parent
- assert isinstance(assignment, astroid.Assign)
- # assignment.expr can be a Name or a Tuple or whatever.
- # Use as_string() for the message
- # FIXME: in case of multiple interfaces, find which one could not
- # be resolved
- self.add_message('unresolved-interface', node=implements,
- args=(node.name, assignment.value.as_string()))
-
def _check_init(self, node):
"""check that the __init__ method call super or ancestors'__init__
method
@@ -943,8 +875,6 @@ a metaclass class method.'}
def _check_signature(self, method1, refmethod, class_type):
"""check that the signature of the two given methods match
-
- class_type is in 'class', 'interface'
"""
if not (isinstance(method1, astroid.Function)
and isinstance(refmethod, astroid.Function)):
diff --git a/pylint/test/input/func_e0206.py b/pylint/test/input/func_e0206.py
deleted file mode 100644
index a9f5790..0000000
--- a/pylint/test/input/func_e0206.py
+++ /dev/null
@@ -1,20 +0,0 @@
-# pylint: disable=R0903
-"""check for interface which are not classes"""
-
-__revision__ = None
-
-class Abcd(object):
- """dummy"""
- __implements__ = __revision__
-
- def __init__(self):
- self.attr = None
-
-class Cdef(object):
- """dummy"""
- __implements__ = (__revision__, Abcd)
-
- def __init__(self):
- pass
-
-
diff --git a/pylint/test/input/func_interfaces.py b/pylint/test/input/func_interfaces.py
deleted file mode 100644
index 29b4603..0000000
--- a/pylint/test/input/func_interfaces.py
+++ /dev/null
@@ -1,112 +0,0 @@
-# pylint:disable=R0201,too-few-public-methods
-"""docstring"""
-from __future__ import print_function
-
-class Interface(object):
- """base class for interfaces"""
-
-class IMachin(Interface):
- """docstring"""
- def truc(self):
- """docstring"""
-
- def troc(self, argument):
- """docstring"""
-
-class Correct1(object):
- """docstring"""
- __implements__ = IMachin
-
- def __init__(self):
- pass
-
- def truc(self):
- """docstring"""
- pass
-
- def troc(self, argument):
- """docstring"""
- pass
-
-class Correct2(object):
- """docstring"""
- __implements__ = (IMachin,)
-
- def __init__(self):
- pass
-
- def truc(self):
- """docstring"""
- pass
-
- def troc(self, argument):
- """docstring"""
- print(argument)
-
-class MissingMethod(object):
- """docstring"""
- __implements__ = IMachin,
-
- def __init__(self):
- pass
-
- def troc(self, argument):
- """docstring"""
- print(argument)
-
- def other(self):
- """docstring"""
-
-class BadArgument(object):
- """docstring"""
- __implements__ = (IMachin,)
-
- def __init__(self):
- pass
-
- def truc(self):
- """docstring"""
- pass
-
- def troc(self):
- """docstring"""
- pass
-
-class InterfaceCantBeFound(object):
- """docstring"""
- __implements__ = undefined
-
- def __init__(self):
- """only to make pylint happier"""
-
- def please(self):
- """public method 1/2"""
-
- def besilent(self):
- """public method 2/2"""
-
-class InterfaceCanNowBeFound(object):
- """docstring"""
- __implements__ = BadArgument.__implements__ + Correct2.__implements__
-
- def __init__(self):
- """only to make pylint happier"""
-
- def please(self):
- """public method 1/2"""
-
- def besilent(self):
- """public method 2/2"""
-
-
-class EmptyImplements(object):
- """no pb"""
- __implements__ = ()
- def __init__(self):
- """only to make pylint happier"""
-
- def please(self):
- """public method 1/2"""
-
- def besilent(self):
- """public method 2/2"""
diff --git a/pylint/test/messages/func_e0206.txt b/pylint/test/messages/func_e0206.txt
deleted file mode 100644
index c15f841..0000000
--- a/pylint/test/messages/func_e0206.txt
+++ /dev/null
@@ -1,3 +0,0 @@
-E: 6:Abcd: Interface resolved to None is not a class
-E: 13:Cdef: Interface resolved to None is not a class
-
diff --git a/pylint/test/messages/func_interfaces.txt b/pylint/test/messages/func_interfaces.txt
deleted file mode 100644
index a4cd21d..0000000
--- a/pylint/test/messages/func_interfaces.txt
+++ /dev/null
@@ -1,6 +0,0 @@
-E: 46:MissingMethod: Missing method 'truc' from IMachin interface
-E: 77:InterfaceCantBeFound: Undefined variable 'undefined'
-E: 88:InterfaceCanNowBeFound: Missing method 'troc' from IMachin interface
-E: 88:InterfaceCanNowBeFound: Missing method 'truc' from IMachin interface
-F: 77:InterfaceCantBeFound: failed to resolve interfaces implemented by InterfaceCantBeFound (undefined)
-W: 71:BadArgument.troc: Arguments number differs from IMachin interface 'troc' method