summaryrefslogtreecommitdiff
path: root/tests/functional/i/invalid/invalid_hash_returned.py
blob: 47f63e99b122eac1d65f45f14504d2a75197ab7f (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
65
66
67
68
69
70
71
"""Check invalid value returned by __hash__ """

# pylint: disable=too-few-public-methods,missing-docstring,no-self-use,import-error, useless-object-inheritance
import six

from missing import Missing


class FirstGoodHash(object):
    """__hash__ returns <type 'int'>"""

    def __hash__(self):
        return 1


class SecondGoodHash(object):
    """__hash__ returns <type 'int'>"""

    def __hash__(self):
        return 0


class HashMetaclass(type):
    def __hash__(cls):
        return 1


@six.add_metaclass(HashMetaclass)
class ThirdGoodHash(object):
    """Hash through the metaclass."""


class FirstBadHash(object):
    """ __hash__ returns a dict """

    def __hash__(self):  # [invalid-hash-returned]
        return {}


class SecondBadHash(object):
    """ __hash__ returns str """

    def __hash__(self):  # [invalid-hash-returned]
        return "True"


class ThirdBadHash(object):
    """ __hash__ returns a float"""

    def __hash__(self):  # [invalid-hash-returned]
        return 1.11


class FourthBadHash(object):
    """ __hash__ returns node which does not have 'value' in AST """

    def __hash__(self):  # [invalid-hash-returned]
        return lambda: 3


class AmbigousHash(object):
    """ Uninferable return value """

    __hash__ = lambda self: Missing


class AnotherAmbiguousHash(object):
    """Potential uninferable return value"""

    def __hash__(self):
        return hash(Missing)