Skip to content

Conversation

@adamsol
Copy link
Contributor

@adamsol adamsol commented Dec 25, 2025

Description

This PR replaces the current power operator hugging implementation, which uses transformers and is quite complicated, with a simpler one, implemented directly in the whitespace function.

The original implementation was created in #2726 and later fixed in #2806, #2874, #3942, #4154. Currently it takes around 150 lines of code, while the new implementation takes around 30 lines.

A minor side-effect of the change is that the whitespace is removed also if the power operator is moved to a separate line, so we'll have 1<newline>**1 instead of 1<newline>** 1. But this shouldn't occur in any normal code and wasn't even tested in the original PR.

Here's how this commit would look like (all deleted lines etc.) without preview mode: adamsol@2444f5c

The main rationale for this refactoring was to extract the condition for power operator hugging into one function, so that the logic could be shared with another change that I want to upload later (edit: #4925). While making it, I also found a small bug related to the power operator (in the visit_factor function), for which I'm planning to submit a separate PR.

Let me know if there could be some specific reason the original implementation did not use the whitespace function, or if I'm missing anything else (this is my first commit here).

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?

@github-actions
Copy link

github-actions bot commented Dec 26, 2025

diff-shades results comparing this PR (6ed4032) to main (a998a18):

--preview style: no changes

--stable style: no changes


What is this? | Workflow run | diff-shades documentation

@cobaltt7
Copy link
Collaborator

cobaltt7 commented Jan 1, 2026

This change looks like an improvement to me, thanks! Will merge after the 2026 style is stabilized, because we want to reduce noise in that release.

Signed-off-by: cobalt <61329810+cobaltt7@users.noreply.github.com>
@cobaltt7 cobaltt7 merged commit 1d233bb into psf:main Jan 23, 2026
56 checks passed
@adamsol adamsol deleted the simplify-power-operator-hugging branch January 23, 2026 18:18
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