google / google/yapf

Multiple Optional return values cause irregular formatting for custom column_limit

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

Description

The yapf configuration:
```
[yapf]
based_on_style = pep8
column_limit = 120
SPLIT_BEFORE_LOGICAL_OPERATOR = true
BLANK_LINE_BEFORE_NESTED_CLASS_OR_DEF = true
SPLIT_COMPLEX_COMPREHENSION = true
SPLIT_BEFORE_BITWISE_OPERATOR = true
SPLIT_BEFORE_ARITHMETIC_OPERATOR = true
SPLIT_ALL_COMMA_SEPARATED_VALUES = true
```

Python 3.9.5
Yapf 0.31.0

When using Optional return values, it seems the custom column limit is ignored. The following is working correctly, because it's under 80 characters.

```
def _retrieve_something_from_db(db_connection: DatabaseConnect,
start: date,
end: date) -> Tuple[Optional[datetime],
Optional[datetime],
Optional[datetime]]:
```

This should work with column limit 120,

```
def _retrieve_something_very_important_from_database(db_connection: DatabaseConnect,
start: date,
end: date) -> Tuple[Optional[datetime],
Optional[datetime],
Optional[datetime]]:
```

but is formatted like this:

```
def _retrieve_something_very_important_from_database(
db_connection: DatabaseConnect,
start: date,
end: date) -> Tuple[Optional[datetime],
Optional[datetime],
Optional[datetime]]:
```

This only happens when we use MULTIPLE Optional keywords.

CORRECTION:
It happens more often. Also with regular function calls without optional arguments.

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.