blob: c459b242feea75d658b4b800634542de9ee45891 (
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
"""Test for statements without effects."""
# pylint: disable=too-few-public-methods, unnecessary-comprehension, unnecessary-ellipsis, use-list-literal
# +1:[pointless-string-statement]
"""inline doc string should use a separated message"""
__revision__ = ''
__revision__ # [pointless-statement]
__revision__ <= 1 # [pointless-statement]
__revision__.lower()
[i for i in __revision__] # [pointless-statement]
# +1:[pointless-string-statement]
"""inline doc string should use a separated message"""
__revision__.lower(); # [unnecessary-semicolon]
list() and tuple() # [expression-not-assigned]
def to_be():
"""return 42"""
return "42"
ANSWER = to_be() # ok
ANSWER == to_be() # [expression-not-assigned]
to_be() or not to_be() # [expression-not-assigned]
to_be().title # [expression-not-assigned]
GOOD_ATTRIBUTE_DOCSTRING = 42
"""Module level attribute docstring is fine. """
class ClassLevelAttributeTest:
""" test attribute docstrings. """
class ClassLevelException(Exception):
"""Exception defined for access as a class attribute."""
good_attribute_docstring = 24
""" class level attribute docstring is fine either. """
second_good_attribute_docstring = 42
# Comments are good.
# empty lines are good, too.
""" Still a valid class level attribute docstring. """
def __init__(self):
self.attr = 42
""" Good attribute docstring """
attr = 24
""" Still a good __init__ level attribute docstring. """
val = 0
for val in range(42):
val += attr
# +1:[pointless-string-statement]
""" Invalid attribute docstring """
self.val = val
def test(self):
""" invalid attribute docstrings here. """
self.val = 42
# +1:[pointless-string-statement]
""" this is an invalid attribute docstring. """
def ellipsis():
"""Test that an Ellipsis as a body does not trigger the error"""
...
class EllipsisBody:
"""Test that an Ellipsis as a body does not trigger the error"""
...
def assigned_exception():
"""Test that an assigned exception is not flagged as a pointless statement"""
exception = ValueError("one")
return exception, ValueError("two")
def raised_exception():
"""Test that a raised exception is not flagged as a pointless statement"""
raise ValueError()
def unraised_exception():
"""Test that instantiating but not raising an exception is flagged as a pointless statement"""
ValueError("pointless-statement") # [pointless-exception-statement]
ValueError(to_be()) # [pointless-exception-statement]
ClassLevelAttributeTest.ClassLevelException(to_be()) # [pointless-exception-statement]
ValueError("another-pointless-statement") # [pointless-exception-statement]
instance = ClassLevelAttributeTest()
instance.ClassLevelException(to_be()) # [pointless-exception-statement]
|