Skip to content

Conversation

@adamsol
Copy link

@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. 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

diff-shades reports zero changes comparing this PR (427b2d9) to main (c3cc5a9).


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

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.

1 participant