aboutsummaryrefslogtreecommitdiff
path: root/tests/functional/i/invalid/s/invalid_str_returned.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/functional/i/invalid/s/invalid_str_returned.py')
-rw-r--r--tests/functional/i/invalid/s/invalid_str_returned.py64
1 files changed, 64 insertions, 0 deletions
diff --git a/tests/functional/i/invalid/s/invalid_str_returned.py b/tests/functional/i/invalid/s/invalid_str_returned.py
new file mode 100644
index 000000000..00ef22046
--- /dev/null
+++ b/tests/functional/i/invalid/s/invalid_str_returned.py
@@ -0,0 +1,64 @@
+"""Check invalid value returned by __str__ """
+
+# pylint: disable=too-few-public-methods,missing-docstring,no-self-use,import-error, useless-object-inheritance
+import six
+
+from missing import Missing
+
+
+class FirstGoodStr(object):
+ """__str__ returns <type 'str'>"""
+
+ def __str__(self):
+ return "some str"
+
+
+class SecondGoodStr(object):
+ """__str__ returns <type 'str'>"""
+
+ def __str__(self):
+ return str(123)
+
+
+class StrMetaclass(type):
+ def __str__(cls):
+ return "some str"
+
+
+@six.add_metaclass(StrMetaclass)
+class ThirdGoodStr(object):
+ """Str through the metaclass."""
+
+
+class FirstBadStr(object):
+ """ __str__ returns bytes """
+
+ def __str__(self): # [invalid-str-returned]
+ return b"123"
+
+
+class SecondBadStr(object):
+ """ __str__ returns int """
+
+ def __str__(self): # [invalid-str-returned]
+ return 1
+
+
+class ThirdBadStr(object):
+ """ __str__ returns node which does not have 'value' in AST """
+
+ def __str__(self): # [invalid-str-returned]
+ return lambda: "some str"
+
+
+class AmbiguousStr(object):
+ """ Uninferable return value """
+
+ __str__ = lambda self: Missing
+
+
+class AnotherAmbiguousStr(object):
+ """Potential uninferable return value"""
+
+ def __str__(self):
+ return str(Missing)