Skip to content

Conversation

@adamsol
Copy link

@adamsol adamsol commented Dec 26, 2025

Description

In a nutshell, this PR turns foo(bar=x + y), where the spacing looks confusing/illogical, into foo(bar=(x + y)).

The general idea is to make whitespace consistent with operator precedence - it is similar in spirit to #157 or #646.

See this short discussion for more details. A few developers agreed that the current formatting is "a little awkward" or would be "worthwhile to fix".

The proposed formatting already exists in a few places in the Black repository:

As well as in other popular Python projects:

I'm interested to hear what you think about this proposal!

PS. This PR shares some logic (is_simple_exponentiation) with #4918. I will rebase one onto another if either is merged first.

Checklist - did you ...

  • Implement any code style changes under the --preview style, following the
    stability policy?
  • Add an entry in CHANGES.md if necessary?
  • Add / update tests if necessary?
  • Add new / update outdated documentation?

@cobaltt7
Copy link
Collaborator

cobaltt7 commented Jan 1, 2026

I'm split on this. I agree in most cases it improves formatting, but it does affect a lot of code. In some cases it feels unnecessary to me (like when the only operator is not or await). Would love to hear other maintainers' opinions!

@adamsol
Copy link
Author

adamsol commented Jan 1, 2026

Thanks for the feedback.

When I ran it locally on the Django codebase, there were around 500 changes, which may seem like a lot, but it's only 0.1% of all ~500k lines of code.

As for not, I've seen some people already parenthesize it, like in the previously linked example from django or another one from numpy. However, the main point of this PR was to add parentheses around binary operations, so we could definitely exclude not/await if this is what other maintainers agree with, just like there's already an exclusion for lambdas (where parentheses also felt unnecessary to me).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants