ARTICLE AD BOX
Maybe you’re not focusing on the right question, the way to best convey your technical ideas to colleagues with minimal friction.
I don’t have a “solves everything“ solution for you. I can tell you that I routinely use black *.py to format code, and it works well for me. If it is a short line, well, so be it. Often I can get the formatting I wish by appending a “magic comma“ at the end of a list of arguments, or by introducing a local variable that is assigned on a separate line.
The Builder pattern in the OP shows up very very often in SQLAlchemy queries. Occasionally, I will see a short query compress to a single line against my wishes, but with ongoing development they often expand to require line splits. Like I said: just embrace the short lines. It’s not worth sweating over. More important development issues will arise to consume your attention.
Consistent formatting in a code base, across contributors, is worth the occasional rough edge, such as what as the OP surfaces.
(I used to be strongly resistant to my team's use of yapf, for years. And then black suddenly broke the log jam by introducing the magic comma — I could get "good enough" results, in a way that is consistent across the commits of all team members. I was able to communicate what matters to PR reviewers in a clear and consistent way.)
want an opinionated, unambiguous code style, but it should not make code unreadable.
So you're saying you really, really don't like the trailing "magic comma"?!? Ok, to each his own. It seems like it's time for you to start hacking on a PR to submit upstream.
main_menu = MainMenu(page=page) ( main_menu.click_on_main_menu( "some entry", ).click_on_main_menu_item( "some-other-entry", ) )Looks fine to me, but opinions will differ.
The following impresses me as "too verbose"; I would prefer to see them all on one line. But it's all under the author's control, by using an extra comma, or not. (Better still, we might loop over the list ["Anton", "Anabelle", "Aaron"].)
( greeter.greet( "Anton", ) .greet( "Anabelle", ) .greet( "Aaron", ) )