google / google/yapf

bad-continuation when using long return type annotation

Open
#481 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
14k
Forks
904
PR merge metrics
No merged PRs in 30d

Description

Hello
I saw today a small issue on yapf 0.20.0 when the return type is specified and very long:

Here is the configuration:
```
[style]
based_on_style = pep8

; knobs
align_closing_bracket_with_visual_indent = true
blank_line_before_class_docstring= true
blank_line_before_nested_class_or_def = true
coalesce_brackets = true
column_limit = 100
dedent_closing_brackets = false
indent_dictionary_value = true
spaces_around_power_operator = false
spaces_before_comment = 2
split_before_first_argument= false
split_before_logical_operator = false
split_penalty_after_opening_bracket = 1000
```

Code is rendered as:
```
from typing import List

def a_very_long_function_name(self, any_arg: List[MyWonderWonderfulComplexName]
) -> List[MyWonderWonderfulComplexName]:
pass
```
pylint then complain:
```
test.py:8 Wrong continued indentation (remove 1 space).
) -> List[MyWonderWonderfulComplexName]:
|^ [bad-continuation]
```
When there is an argument to print on the same line than the closing parenthesis, yes an extra space is needed, but otherwise, pylint does not want the extra space, so parenthesis are aligned.
Should be:
```
def a_very_long_function_name(self, any_arg: List[MyWonderWonderfulComplexName]
) -> List[MyWonderWonderfulComplexName]:
pass
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.