blob: e57db529063c07e99defca5bb1ee20dea5ab3a86 (
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 __len__ """
# pylint: disable=too-few-public-methods,missing-docstring,no-self-use,import-error, useless-object-inheritance
import sys
import six
from missing import Missing
class FirstGoodLen(object):
"""__len__ returns <type 'int'>"""
def __len__(self):
return 0
class SecondGoodLen(object):
"""__len__ returns <type 'long'>"""
def __len__(self):
return sys.maxsize + 1
class LenMetaclass(type):
def __len__(cls):
return 1
@six.add_metaclass(LenMetaclass)
class ThirdGoodLen(object):
"""Length through the metaclass."""
class FirstBadLen(object):
""" __len__ returns a negative integer """
def __len__(self): # [invalid-length-returned]
return -1
class SecondBadLen(object):
""" __len__ returns non-int """
def __len__(self): # [invalid-length-returned]
return 3.0
class ThirdBadLen(object):
""" __len__ returns node which does not have 'value' in AST """
def __len__(self): # [invalid-length-returned]
return lambda: 3
class AmbigousLen(object):
""" Uninferable return value """
__len__ = lambda self: Missing
class AnotherAmbiguousLen(object):
"""Potential uninferable return value"""
def __len__(self):
return int(Missing)
|