blob: 5ba8325231850f2e7d1a816ce5dd12e6da934853 (
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 __bytes__ """
# pylint: disable=too-few-public-methods,missing-docstring,import-error,unnecessary-lambda-assignment
import six
from missing import Missing
class FirstGoodBytes:
"""__bytes__ returns <type 'bytes'>"""
def __bytes__(self):
return b"some bytes"
class SecondGoodBytes:
"""__bytes__ returns <type 'bytes'>"""
def __bytes__(self):
return bytes("123", "ascii")
class BytesMetaclass(type):
def __bytes__(cls):
return b"some bytes"
@six.add_metaclass(BytesMetaclass)
class ThirdGoodBytes:
"""Bytes through the metaclass."""
class FirstBadBytes:
""" __bytes__ returns bytes """
def __bytes__(self): # [invalid-bytes-returned]
return "123"
class SecondBadBytes:
""" __bytes__ returns int """
def __bytes__(self): # [invalid-bytes-returned]
return 1
class ThirdBadBytes:
""" __bytes__ returns node which does not have 'value' in AST """
def __bytes__(self): # [invalid-bytes-returned]
return lambda: b"some bytes"
class AmbiguousBytes:
""" Uninferable return value """
__bytes__ = lambda self: Missing
class AnotherAmbiguousBytes:
"""Potential uninferable return value"""
def __bytes__(self):
return bytes(Missing)
|