summaryrefslogtreecommitdiff
path: root/tests/functional/i/invalid/invalid_str_returned.py
blob: dac98b50a63a43cce43d6411eb9a27c2c2d492e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"""Check invalid value returned by __str__ """

# pylint: disable=too-few-public-methods,missing-docstring,import-error,useless-object-inheritance,unnecessary-lambda-assignment
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)