google / google/yapf

Add parentheisis and prefer splitting on long function chaining

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

Description

Often when chaining functions, e.g. long queries/maps/reduce, it's easy to get ugly code... see for example this [SO question](http://stackoverflow.com/q/34079590/1240268)!

```
a.this_is_looooooooooooooooooooooooooong_identifier.something_even_looooooooooonger_potentially.and_a_final_pretty_looooong_one
```

I think the preferred formatting is to insert parenthesis:

```
(a.this_is_looooooooooooooooooooooooooong_identifier
.something_even_looooooooooonger_potentially
.and_a_final_pretty_looooong_one
)
```

Indeed, even if you have already inserted the paren as above yapf "fixes" to:

```
(a.this_is_looooooooooooooooooooooooooong_identifier.something_even_looooooooooonger_potentially.and_a_final_pretty_looooong_one)
```

*Note: I suspect this is pretty speculative :)

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.