Simplify power operator hugging implementation #4918
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
whitespacefunction.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>**1instead of1<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_factorfunction), 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
whitespacefunction, or if I'm missing anything else (this is my first commit here).Checklist - did you ...
--previewstyle, following thestability policy?
CHANGES.mdif necessary?