blob: ec428b4b31d592ef40e79698aaed4ac5216b3ba4 (
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 __format__ """
# pylint: disable=too-few-public-methods,missing-docstring,no-self-use,import-error, useless-object-inheritance
import six
from missing import Missing
class FirstGoodFormat(object):
"""__format__ returns <type 'str'>"""
def __format__(self, format_spec):
return "some format"
class SecondGoodFormat(object):
"""__format__ returns <type 'str'>"""
def __format__(self, format_spec):
return str(123)
class FormatMetaclass(type):
def __format__(cls, format_spec):
return "some format"
@six.add_metaclass(FormatMetaclass)
class ThirdGoodFormat(object):
"""Format through the metaclass."""
class FirstBadFormat(object):
""" __format__ returns bytes """
def __format__(self, format_spec): # [invalid-format-returned]
return b"123"
class SecondBadFormat(object):
""" __format__ returns int """
def __format__(self, format_spec): # [invalid-format-returned]
return 1
class ThirdBadFormat(object):
""" __format__ returns node which does not have 'value' in AST """
def __format__(self, format_spec): # [invalid-format-returned]
return lambda: "some format"
class AmbiguousFormat(object):
""" Uninferable return value """
__format__ = lambda self, format_spec: Missing
class AnotherAmbiguousFormat(object):
"""Potential uninferable return value"""
def __format__(self, format_spec):
return str(Missing)
|