summaryrefslogtreecommitdiff
path: root/tests/functional/i/invalid/invalid_bool_returned.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/functional/i/invalid/invalid_bool_returned.py')
-rw-r--r--tests/functional/i/invalid/invalid_bool_returned.py62
1 files changed, 62 insertions, 0 deletions
diff --git a/tests/functional/i/invalid/invalid_bool_returned.py b/tests/functional/i/invalid/invalid_bool_returned.py
new file mode 100644
index 000000000..0e68ed263
--- /dev/null
+++ b/tests/functional/i/invalid/invalid_bool_returned.py
@@ -0,0 +1,62 @@
+"""Check invalid value returned by __bool__ """
+
+# pylint: disable=too-few-public-methods,missing-docstring,no-self-use,import-error, useless-object-inheritance
+import six
+
+from missing import Missing
+
+
+class FirstGoodBool(object):
+ """__bool__ returns <type 'bool'>"""
+
+ def __bool__(self):
+ return True
+
+
+class SecondGoodBool(object):
+ """__bool__ returns <type 'bool'>"""
+
+ def __bool__(self):
+ return bool(0)
+
+
+class BoolMetaclass(type):
+ def __bool__(cls):
+ return True
+
+
+@six.add_metaclass(BoolMetaclass)
+class ThirdGoodBool(object):
+ """Bool through the metaclass."""
+
+
+class FirstBadBool(object):
+ """ __bool__ returns an integer """
+
+ def __bool__(self): # [invalid-bool-returned]
+ return 1
+
+
+class SecondBadBool(object):
+ """ __bool__ returns str """
+
+ def __bool__(self): # [invalid-bool-returned]
+ return "True"
+
+
+class ThirdBadBool(object):
+ """ __bool__ returns node which does not have 'value' in AST """
+
+ def __bool__(self): # [invalid-bool-returned]
+ return lambda: 3
+
+
+class AmbigousBool(object):
+ """ Uninferable return value """
+ __bool__ = lambda self: Missing
+
+
+class AnotherAmbiguousBool(object):
+ """Potential uninferable return value"""
+ def __bool__(self):
+ return bool(Missing)