Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

bad_continuation.py 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. """Regression test case for bad-continuation."""
  2. # pylint: disable=print-statement,using-constant-test
  3. # Various alignment for brackets
  4. from __future__ import print_function
  5. LIST0 = [
  6. 1, 2, 3
  7. ]
  8. LIST1 = [
  9. 1, 2, 3
  10. ]
  11. LIST2 = [
  12. 1, 2, 3
  13. ] # [bad-continuation]
  14. # Alignment inside literals
  15. W0 = [1, 2, 3,
  16. 4, 5, 6,
  17. 7, # [bad-continuation]
  18. 8, 9, 10,
  19. 11, 12, 13,
  20. # and a comment
  21. 14, 15, 16]
  22. W1 = {
  23. 'a': 1,
  24. 'b': 2, # [bad-continuation]
  25. 'c': 3,
  26. }
  27. W2 = {
  28. 'a': 1,
  29. 'b': 2, # [bad-continuation]
  30. 'c': 3,
  31. }
  32. W2 = ['some', 'contents' # with a continued comment that may be aligned
  33. # under the previous comment (optionally)
  34. 'and',
  35. 'more', # but this
  36. # [bad-continuation] is not accepted
  37. 'contents', # [bad-continuation] nor this.
  38. ]
  39. # Values in dictionaries should be indented 4 spaces further if they are on a
  40. # different line than their key
  41. W4 = {
  42. 'key1':
  43. 'value1', # Grandfather in the old style
  44. 'key2':
  45. 'value2', # [bad-continuation]
  46. 'key3':
  47. 'value3', # Comma here
  48. }
  49. # And should follow the same rules as continuations within parens
  50. W5 = {
  51. 'key1': 'long value'
  52. 'long continuation',
  53. 'key2': 'breaking'
  54. 'wrong', # [bad-continuation]
  55. 'key3': 2*(
  56. 2+2),
  57. 'key4': ('parenthesis',
  58. 'continuation') # No comma here
  59. }
  60. # Allow values to line up with their keys when the key is next to the brace
  61. W6 = {'key1':
  62. 'value1',
  63. 'key2':
  64. 'value2',
  65. }
  66. # Or allow them to be indented
  67. W7 = {'key1':
  68. 'value1',
  69. 'key2':
  70. 'value2'
  71. }
  72. # Bug that caused a warning on the previous two cases permitted these odd
  73. # incorrect indentations
  74. W8 = {'key1':
  75. 'value1', # [bad-continuation]
  76. }
  77. W9 = {'key1':
  78. 'value1', # [bad-continuation]
  79. }
  80. # Alignment of arguments in function definitions
  81. def continue1(some_arg,
  82. some_other_arg):
  83. """A function with well-aligned arguments."""
  84. print(some_arg, some_other_arg)
  85. def continue2(
  86. some_arg,
  87. some_other_arg):
  88. """A function with well-aligned arguments."""
  89. print(some_arg, some_other_arg)
  90. def continue3(
  91. some_arg, # [bad-continuation]
  92. some_other_arg): # [bad-continuation]
  93. """A function with misaligned arguments"""
  94. print(some_arg, some_other_arg)
  95. def continue4( # pylint:disable=missing-docstring
  96. arg1,
  97. arg2): print(arg1, arg2)
  98. def callee(*args):
  99. """noop"""
  100. print(args)
  101. callee(
  102. "a",
  103. "b"
  104. )
  105. callee("a",
  106. "b") # [bad-continuation]
  107. callee(5, {'a': 'b',
  108. 'c': 'd'})
  109. if (
  110. 1
  111. ): pass
  112. if (
  113. 1
  114. ): pass
  115. if (
  116. 1
  117. ): pass # [bad-continuation]
  118. if (1 and
  119. 2): # [bad-continuation]
  120. pass
  121. while (1 and
  122. 2):
  123. pass
  124. while (1 and
  125. 2 and # [bad-continuation]
  126. 3):
  127. pass
  128. if (
  129. 2): pass # [bad-continuation]
  130. if (1 or
  131. 2 or
  132. 3): pass
  133. if (1 or
  134. 2 or # [bad-continuation]
  135. 3): print(1, 2)
  136. if (1 and
  137. 2): pass # [bad-continuation]
  138. if (
  139. 2): pass
  140. if (
  141. 2): # [bad-continuation]
  142. pass
  143. L1 = (lambda a,
  144. b: a + b)
  145. if not (1 and
  146. 2):
  147. print(3)
  148. if not (1 and
  149. 2): # [bad-continuation]
  150. print(3)
  151. continue2("foo",
  152. some_other_arg="this "
  153. "is "
  154. "fine")