summaryrefslogtreecommitdiff
path: root/pylint/test/functional/bad_continuation.py
blob: 34292abe02391744f1c1197a7e31ecbd25a75437 (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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
"""Regression test case for bad-continuation."""
# pylint: disable=print-statement,using-constant-test
# Various alignment for brackets
from __future__ import print_function

LIST0 = [
    1, 2, 3
]
LIST1 = [
    1, 2, 3
    ]
LIST2 = [
    1, 2, 3
   ]  # [bad-continuation]

# Alignment inside literals
W0 = [1, 2, 3,
      4, 5, 6,
         7,  # [bad-continuation]
      8, 9, 10,
      11, 12, 13,
      # and a comment
      14, 15, 16]

W1 = {
    'a': 1,
   'b': 2,  # [bad-continuation]
    'c': 3,
    }

W2 = {
    'a': 1,
   'b': 2,  # [bad-continuation]
    'c': 3,
    }

W2 = ['some', 'contents'  # with a continued comment that may be aligned
                          # under the previous comment (optionally)
      'and',
      'more',             # but this
                             # [bad-continuation] is not accepted
                          'contents', # [bad-continuation] nor this.
     ]

# Values in dictionaries should be indented 4 spaces further if they are on a
# different line than their key
W4 = {
    'key1':
    'value1',  # Grandfather in the old style
    'key2':
      'value2',  # [bad-continuation]
    'key3':
        'value3',  # Comma here
    }

# And should follow the same rules as continuations within parens
W5 = {
    'key1': 'long value'
            'long continuation',
    'key2': 'breaking'
        'wrong',  # [bad-continuation]
    'key3': 2*(
        2+2),
    'key4': ('parenthesis',
             'continuation')  # No comma here
    }

# Allow values to line up with their keys when the key is next to the brace
W6 = {'key1':
      'value1',
      'key2':
      'value2',
     }

# Or allow them to be indented
W7 = {'key1':
          'value1',
      'key2':
          'value2'
     }

# Bug that caused a warning on the previous two cases permitted these odd
# incorrect indentations
W8 = {'key1':
'value1',  # [bad-continuation]
     }

W9 = {'key1':
    'value1',  # [bad-continuation]
     }

# Alignment of arguments in function definitions
def continue1(some_arg,
              some_other_arg):
    """A function with well-aligned arguments."""
    print(some_arg, some_other_arg)


def continue2(
        some_arg,
        some_other_arg):
    """A function with well-aligned arguments."""
    print(some_arg, some_other_arg)

def continue3(
    some_arg,         # [bad-continuation]
    some_other_arg):  # [bad-continuation]
    """A function with misaligned arguments"""
    print(some_arg, some_other_arg)

def continue4(  # pylint:disable=missing-docstring
    arg1,
    arg2): print(arg1, arg2)


def callee(*args):
    """noop"""
    print(args)


callee(
    "a",
    "b"
    )

callee("a",
    "b")  # [bad-continuation]

callee(5, {'a': 'b',
           'c': 'd'})

if (
    1
    ): pass

if (
    1
): pass
if (
    1
   ): pass  # [bad-continuation]

if (1 and
    2):  # [bad-continuation]
    pass

while (1 and
       2):
    pass

while (1 and
         2 and  # [bad-continuation]
       3):
    pass

if (
  2): pass  # [bad-continuation]

if (1 or
    2 or
    3): pass

if (1 or
     2 or  # [bad-continuation]
    3): print(1, 2)

if (1 and
  2): pass  # [bad-continuation]

if (
    2): pass

if (
  2):  # [bad-continuation]
    pass

L1 = (lambda a,
             b: a + b)

if not (1 and
        2):
    print(3)

if not (1 and
    2):  # [bad-continuation]
    print(3)

continue2("foo",
          some_other_arg="this "
                         "is "
                         "fine")