blob: f97d0f29d5ecf46eb533c3ff4e445c8614d7d8fe (
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,import-error,unnecessary-lambda-assignment
import six
from missing import Missing
class FirstGoodFormat:
"""__format__ returns <type 'str'>"""
def __format__(self, format_spec):
return "some format"
class SecondGoodFormat:
"""__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:
"""Format through the metaclass."""
class FirstBadFormat:
""" __format__ returns bytes """
def __format__(self, format_spec): # [invalid-format-returned]
return b"123"
class SecondBadFormat:
""" __format__ returns int """
def __format__(self, format_spec): # [invalid-format-returned]
return 1
class ThirdBadFormat:
""" __format__ returns node which does not have 'value' in AST """
def __format__(self, format_spec): # [invalid-format-returned]
return lambda: "some format"
class AmbiguousFormat:
""" Uninferable return value """
__format__ = lambda self, format_spec: Missing
class AnotherAmbiguousFormat:
"""Potential uninferable return value"""
def __format__(self, format_spec):
return str(Missing)
|