question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Intentional call chain with explicit parenthesis not respected

See original GitHub issue

Describe the bug

return (
    flu(files)
    .map(to_path)
    .flatten()
    .collect()  # type: ignore
)

this becomes

return flu(files).map(to_path).flatten().collect()  # type: ignore

this.

To Reproduce Run above code with these arguments:

$ black --target-version py310 -- test.py

Expected behavior

intentional parenthesis around method chains should be respected and not break into single statement.

Environment

  • Black’s version: main
  • OS and Python version: Linux/Python 3.10.4

Additional context

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5

github_iconTop GitHub Comments

4reactions
JelleZijlstracommented, Jun 4, 2022

I’m inclined to keep the current behavior. Black generally tries to put things in one line where possible.

1reaction
felix-hildencommented, Jun 9, 2022

I agree with Jelle, we don’t want to take previous formatting into account any more than is absolutely necessary. Introducing another magic trailing comma does not sound good.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Should I fully parenthesize expressions or rely on precedence ...
Yes. You should always use parentheses... you do not control the order of precedence... the ...
Read more >
Ambiguous PEMDAS - Harvard Mathematics Department
"If no parentheses are present, multiply and divide before adding and subtracting." This is a very rough rule but it has the advantage...
Read more >
method call without parenthesis doesn't forward all arguments ...
I need to understand why sometimes when a method call is made with parenthesis to initialize a base class, for instance, it doesn't...
Read more >
Expressions and Control Structures - Solidity
Calling the function g via either way results in it being called “externally”, using a message call and not directly via jumps. Please...
Read more >
PSR-12: Extended Coding Style - PHP-FIG
When instantiating a new class, parentheses MUST always be present even when there are no arguments passed to the constructor. new Foo();. 4.1...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found