Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion pycodestyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,33 @@ def _is_one_liner(logical_line, indent_level, lines, line_number):
return expand_indent(lines[next_idx]) <= indent_level


def _is_one_line_def_stub(tokens):
meaningful_tokens = [
(token_type, text)
for token_type, text, *_ in tokens
if token_type not in (
tokenize.COMMENT,
tokenize.DEDENT,
tokenize.INDENT,
tokenize.NL,
tokenize.NEWLINE,
)
]
if len(meaningful_tokens) < 3:
return False

if meaningful_tokens[:2] == [
(tokenize.NAME, 'async'), (tokenize.NAME, 'def')]:
starts_with_def = True
else:
starts_with_def = meaningful_tokens[0] == (tokenize.NAME, 'def')

return (
starts_with_def and
meaningful_tokens[-2:] == [(tokenize.OP, ':'), (tokenize.OP, '...')]
)


@register_check
def blank_lines(logical_line, blank_lines, indent_level, line_number,
blank_before, previous_logical,
Expand Down Expand Up @@ -590,7 +617,7 @@ def continued_indentation(logical_line, tokens, indent_level, hang_closing,
# that it is indented by 4 spaces, then we should not allow 4-space
# indents on the final continuation line; in turn, some other
# indents are allowed to have an extra 4 spaces.
indent_next = logical_line.endswith(':')
indent_next = logical_line.endswith(':') or _is_one_line_def_stub(tokens)

row = depth = 0
valid_hangs = (indent_size,) if indent_char != '\t' \
Expand Down
10 changes: 10 additions & 0 deletions testing/data/E12not.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,3 +659,13 @@ def f1():
open('/path/to/some/file/being/written', 'w') as file_2, \
open('just-making-sure-more-continuations-also-work'):
file_2.write(file_1.read())
#: E704:5:5
from typing import Protocol


class _LongPollProtocol(Protocol):
def __call__(
self,
foo: str,
bar: int,
) -> int: ...
Loading