summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSylvain Thénault <sylvain.thenault@logilab.fr>2013-12-20 17:32:06 +0100
committerSylvain Thénault <sylvain.thenault@logilab.fr>2013-12-20 17:32:06 +0100
commit6eae182ae69c45213065a89b657ea7b6f1ace658 (patch)
treef5373c92d05fc318ac9dcc46cd175f05b6f22543
parent604d7146db0a335884a07b4adba634c8de96f609 (diff)
downloadpylint-git-6eae182ae69c45213065a89b657ea7b6f1ace658.tar.gz
drop badly-implemented-container which cause several problems in its current implementation.
Somewhat close #112 (among other reporter problems).
-rw-r--r--ChangeLog4
-rw-r--r--checkers/design_analysis.py47
-rw-r--r--test/input/func_method_could_be_function.py2
-rw-r--r--test/input/func_special_methods.py55
-rw-r--r--test/messages/func_special_methods.txt6
-rw-r--r--test/regrtest_data/pygtk_import.py2
6 files changed, 6 insertions, 110 deletions
diff --git a/ChangeLog b/ChangeLog
index 5c49765c2..f4073c321 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -43,6 +43,10 @@ ChangeLog for Pylint
* don't mark `input` as a bad function when using python3 (#110).
+ * badly-implemented-container caused several problems in its
+ current implementation. Deactivate it until we have something
+ better. See #112 for instance.
+
2013-08-06 -- 1.0.0
diff --git a/checkers/design_analysis.py b/checkers/design_analysis.py
index f3b58821e..ca201f351 100644
--- a/checkers/design_analysis.py
+++ b/checkers/design_analysis.py
@@ -26,42 +26,6 @@ import re
# regexp for ignored argument name
IGNORED_ARGUMENT_NAMES = re.compile('_.*')
-SPECIAL_METHODS = [('Context manager', set(('__enter__',
- '__exit__',))),
- ('Container', set(('__len__',
- '__getitem__',))),
- ('Mutable container', set(('__setitem__',
- '__delitem__',))),
- ]
-
-class SpecialMethodChecker(object):
- """A functor that checks for consistency of a set of special methods"""
- def __init__(self, methods_found, on_error):
- """Stores the set of __x__ method names that were found in the
- class and a callable that will be called with args to R0024 if
- the check fails
- """
- self.methods_found = methods_found
- self.on_error = on_error
-
- def __call__(self, methods_required, protocol):
- """Checks the set of method names given to __init__ against the set
- required.
-
- If they are all present, returns true.
- If they are all absent, returns false.
- If some are present, reports the error and returns false.
- """
- required_methods_found = methods_required & self.methods_found
- if required_methods_found == methods_required:
- return True
- if required_methods_found:
- required_methods_missing = methods_required - self.methods_found
- self.on_error((protocol,
- ', '.join(sorted(required_methods_found)),
- ', '.join(sorted(required_methods_missing))))
- return False
-
def class_is_abstract(klass):
"""return true if the given class node should be considered as an abstract
@@ -121,10 +85,6 @@ MSGS = {
'R0923': ('Interface not implemented',
'interface-not-implemented',
'Used when an interface class is not implemented anywhere.'),
- 'R0924': ('Badly implemented %s, implements %s but not %s',
- 'incomplete-protocol',
- 'A class implements some of the special methods for a particular \
- protocol, but not all of them')
}
@@ -289,13 +249,6 @@ class MisdesignChecker(BaseChecker):
# stop here for exception, metaclass and interface classes
if node.type != 'class':
return
- # Does the class implement special methods consitently?
- # If so, don't enforce minimum public methods.
- check_special = SpecialMethodChecker(
- special_methods, lambda args: self.add_message('R0924', node=node, args=args))
- protocols = [check_special(pmethods, pname) for pname, pmethods in SPECIAL_METHODS]
- if True in protocols:
- return
# Does the class contain more than 5 public methods ?
if nb_public_methods < self.config.min_public_methods:
self.add_message('R0903', node=node,
diff --git a/test/input/func_method_could_be_function.py b/test/input/func_method_could_be_function.py
index 47b0fc50b..a28e48a1b 100644
--- a/test/input/func_method_could_be_function.py
+++ b/test/input/func_method_could_be_function.py
@@ -1,4 +1,4 @@
-# pylint: disable=R0903,R0922,W0232,R0924
+# pylint: disable=R0903,R0922,W0232
"""test detection of method which could be a function"""
__revision__ = None
diff --git a/test/input/func_special_methods.py b/test/input/func_special_methods.py
deleted file mode 100644
index 1b30e269f..000000000
--- a/test/input/func_special_methods.py
+++ /dev/null
@@ -1,55 +0,0 @@
-#pylint: disable=C0111
-__revision__ = None
-
-class ContextManager(object):
- def __enter__(self):
- pass
- def __exit__(self, *args):
- pass
- def __init__(self):
- pass
-
-class BadContextManager(object):
- def __enter__(self):
- pass
- def __init__(self):
- pass
-
-class Container(object):
- def __init__(self):
- pass
- def __len__(self):
- return 0
- def __getitem__(self, key):
- pass
- def __setitem__(self, key, value):
- pass
- def __delitem__(self, key, value):
- pass
- def __iter__(self):
- pass
-
-class BadROContainer(object):
- def __init__(self):
- pass
- def __len__(self):
- return 0
- def __setitem__(self, key, value):
- pass
- def __iter__(self):
- pass
-
-
-class BadContainer(object):
- def __init__(self):
- pass
- def __len__(self):
- return 0
- def __getitem__(self, key, value):
- pass
- def __setitem__(self, key, value):
- pass
-
-class MyTuple(tuple):
- def __getitem__(self, index):
- return super(MyTuple, self).__getitem__(index)
diff --git a/test/messages/func_special_methods.txt b/test/messages/func_special_methods.txt
deleted file mode 100644
index f7e88ae92..000000000
--- a/test/messages/func_special_methods.txt
+++ /dev/null
@@ -1,6 +0,0 @@
-R: 12:BadContextManager: Badly implemented Context manager, implements __enter__ but not __exit__
-R: 12:BadContextManager: Too few public methods (0/2)
-R: 32:BadROContainer: Badly implemented Container, implements __len__ but not __getitem__
-R: 32:BadROContainer: Badly implemented Mutable container, implements __setitem__ but not __delitem__
-R: 32:BadROContainer: Too few public methods (0/2)
-R: 43:BadContainer: Badly implemented Mutable container, implements __setitem__ but not __delitem__
diff --git a/test/regrtest_data/pygtk_import.py b/test/regrtest_data/pygtk_import.py
index 26f9e711e..974035eb4 100644
--- a/test/regrtest_data/pygtk_import.py
+++ b/test/regrtest_data/pygtk_import.py
@@ -1,4 +1,4 @@
-#pylint: disable=R0903,R0904,R0924
+#pylint: disable=R0903,R0904
"""#10026"""
__revision__ = 1
from gtk import VBox