@@ -536,6 +536,17 @@ def __post_init__(self) -> None:
536
536
self .visit_case_block = self .visit_match_case
537
537
538
538
539
+ def _hugging_power_ops_line_to_string (
540
+ line : Line ,
541
+ features : Collection [Feature ],
542
+ mode : Mode ,
543
+ ) -> Optional [str ]:
544
+ try :
545
+ return line_to_string (next (hug_power_op (line , features , mode )))
546
+ except CannotTransform :
547
+ return None
548
+
549
+
539
550
def transform_line (
540
551
line : Line , mode : Mode , features : Collection [Feature ] = ()
541
552
) -> Iterator [Line ]:
@@ -551,6 +562,14 @@ def transform_line(
551
562
552
563
line_str = line_to_string (line )
553
564
565
+ # We need the line string when power operators are hugging to determine if we should
566
+ # split the line. Default to line_str, if no power operator are present on the line.
567
+ line_str_hugging_power_ops = (
568
+ (_hugging_power_ops_line_to_string (line , features , mode ) or line_str )
569
+ if Preview .fix_power_op_line_length in mode
570
+ else line_str
571
+ )
572
+
554
573
ll = mode .line_length
555
574
sn = mode .string_normalization
556
575
string_merge = StringMerger (ll , sn )
@@ -564,7 +583,7 @@ def transform_line(
564
583
and not line .should_split_rhs
565
584
and not line .magic_trailing_comma
566
585
and (
567
- is_line_short_enough (line , mode = mode , line_str = line_str )
586
+ is_line_short_enough (line , mode = mode , line_str = line_str_hugging_power_ops )
568
587
or line .contains_unsplittable_type_ignore ()
569
588
)
570
589
and not (line .inside_brackets and line .contains_standalone_comments ())
0 commit comments