summaryrefslogtreecommitdiff
path: root/pylint/test
diff options
context:
space:
mode:
authorDmitry Pribysh <dmand@yandex.ru>2015-10-27 18:03:15 +0300
committerDmitry Pribysh <dmand@yandex.ru>2015-10-27 18:03:15 +0300
commit4f85cfbec5bd5576754274adb351116e164bc19a (patch)
treead255a14205ddfcdbfbc1a56c768bf467ab5153c /pylint/test
parent328f24b72197c1a8ac22a58357f67740d6e1dd94 (diff)
downloadpylint-4f85cfbec5bd5576754274adb351116e164bc19a.tar.gz
Make iterable checker skip classes that are inferred to be abstractfix-685
Diffstat (limited to 'pylint/test')
-rw-r--r--pylint/test/functional/iterable_context.py18
-rw-r--r--pylint/test/functional/mapping_context.py40
-rw-r--r--pylint/test/functional/membership_protocol.py46
-rw-r--r--pylint/test/functional/membership_protocol.txt14
4 files changed, 105 insertions, 13 deletions
diff --git a/pylint/test/functional/iterable_context.py b/pylint/test/functional/iterable_context.py
index 9c5d1b6..fa4e617 100644
--- a/pylint/test/functional/iterable_context.py
+++ b/pylint/test/functional/iterable_context.py
@@ -149,7 +149,10 @@ class BaseType(object):
return True
else:
# error should not be emitted here
- return value in self.valid_values
+ for v in self.valid_values:
+ if value == v:
+ return True
+ return False
class AbstractUrlMarkManager(object):
def __init__(self):
@@ -161,3 +164,16 @@ class AbstractUrlMarkManager(object):
def _init_lineparser(self):
raise NotImplementedError
+
+# class is not named as abstract
+# but still is deduceably abstract
+class UrlMarkManager(object):
+ def __init__(self):
+ self._lineparser = None
+ self._init_lineparser()
+ # error should not be emitted here
+ for line in self._lineparser:
+ print(line)
+
+ def _init_lineparser(self):
+ raise NotImplementedError
diff --git a/pylint/test/functional/mapping_context.py b/pylint/test/functional/mapping_context.py
index cfab8dc..72457b8 100644
--- a/pylint/test/functional/mapping_context.py
+++ b/pylint/test/functional/mapping_context.py
@@ -36,7 +36,7 @@ class NotMapping(object):
test(**NotMapping()) # [not-a-mapping]
-# skip checks if statement is inside mixin class
+# skip checks if statement is inside mixin/base/abstract class
class SomeMixin(object):
kwargs = None
@@ -50,6 +50,44 @@ class SomeMixin(object):
kws = self.get_kwargs()
self.run(**kws)
+class AbstractThing(object):
+ kwargs = None
+
+ def get_kwargs(self):
+ return self.kwargs
+
+ def run(self, **kwargs):
+ print(kwargs)
+
+ def dispatch(self):
+ kws = self.get_kwargs()
+ self.run(**kws)
+
+class BaseThing(object):
+ kwargs = None
+
+ def get_kwargs(self):
+ return self.kwargs
+
+ def run(self, **kwargs):
+ print(kwargs)
+
+ def dispatch(self):
+ kws = self.get_kwargs()
+ self.run(**kws)
+
+# abstract class
+class Thing(object):
+ def get_kwargs(self):
+ raise NotImplementedError
+
+ def run(self, **kwargs):
+ print(kwargs)
+
+ def dispatch(self):
+ kwargs = self.get_kwargs()
+ self.run(**kwargs)
+
# skip uninferable instances
from some_missing_module import Mapping
diff --git a/pylint/test/functional/membership_protocol.py b/pylint/test/functional/membership_protocol.py
index 7b3a46f..0fd4886 100644
--- a/pylint/test/functional/membership_protocol.py
+++ b/pylint/test/functional/membership_protocol.py
@@ -5,9 +5,9 @@
1 in {'a': 1, 'b': 2}
1 in {1, 2, 3}
1 in (1, 2, 3)
-1 in "123"
-1 in u"123"
-1 in bytearray(b"123")
+'1' in "123"
+'1' in u"123"
+'1' in bytearray(b"123")
1 in frozenset([1, 2, 3])
# comprehensions
@@ -59,7 +59,7 @@ class MaybeIterable(ImportedClass):
10 in MaybeIterable()
-# do not emit warning inside mixins
+# do not emit warning inside mixins/abstract/base classes
class UsefulMixin(object):
stuff = None
@@ -71,6 +71,44 @@ class UsefulMixin(object):
if thing in stuff:
pass
+class BaseThing(object):
+ valid_values = None
+
+ def validate(self, value):
+ if self.valid_values is None:
+ return True
+ else:
+ # error should not be emitted here
+ return value in self.valid_values
+
+class AbstractThing(object):
+ valid_values = None
+
+ def validate(self, value):
+ if self.valid_values is None:
+ return True
+ else:
+ # error should not be emitted here
+ return value in self.valid_values
+
+# class is not named as abstract
+# but still is deduceably abstract
+class Thing(object):
+ valid_values = None
+
+ def __init__(self):
+ self._init_values()
+
+ def validate(self, value):
+ if self.valid_values is None:
+ return True
+ else:
+ # error should not be emitted here
+ return value in self.valid_values
+
+ def _init_values(self):
+ raise NotImplementedError
+
# error cases
42 in 42 # [unsupported-membership-test]
42 not in None # [unsupported-membership-test]
diff --git a/pylint/test/functional/membership_protocol.txt b/pylint/test/functional/membership_protocol.txt
index 6e9bd8e..edb2227 100644
--- a/pylint/test/functional/membership_protocol.txt
+++ b/pylint/test/functional/membership_protocol.txt
@@ -1,7 +1,7 @@
-unsupported-membership-test:75::Value '42' doesn't support membership test
-unsupported-membership-test:76::Value 'None' doesn't support membership test
-unsupported-membership-test:77::Value '8.5' doesn't support membership test
-unsupported-membership-test:82::Value 'EmptyClass()' doesn't support membership test
-unsupported-membership-test:83::Value 'EmptyClass' doesn't support membership test
-unsupported-membership-test:84::Value 'count' doesn't support membership test
-unsupported-membership-test:85::Value 'range' doesn't support membership test
+unsupported-membership-test:113::Value '42' doesn't support membership test
+unsupported-membership-test:114::Value 'None' doesn't support membership test
+unsupported-membership-test:115::Value '8.5' doesn't support membership test
+unsupported-membership-test:120::Value 'EmptyClass()' doesn't support membership test
+unsupported-membership-test:121::Value 'EmptyClass' doesn't support membership test
+unsupported-membership-test:122::Value 'count' doesn't support membership test
+unsupported-membership-test:123::Value 'range' doesn't support membership test