summaryrefslogtreecommitdiff
path: root/pylint/test/functional/membership_protocol.py
diff options
context:
space:
mode:
Diffstat (limited to 'pylint/test/functional/membership_protocol.py')
-rw-r--r--pylint/test/functional/membership_protocol.py46
1 files changed, 42 insertions, 4 deletions
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]