blob: 0e68ed2636e3bc7ad2328e9c3e22ba2dc2a830af (
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
|
"""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)
|