diff --git a/crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/binary_pow_spacing.py b/crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/binary_pow_spacing.py new file mode 100644 index 0000000000..1f7c1c2542 --- /dev/null +++ b/crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/binary_pow_spacing.py @@ -0,0 +1,10 @@ +# No spacing +5 ** 5 +5.0 ** 5.0 +1e5 ** 2e5 +True ** True +False ** False +None ** None + +# Space +"a" ** "b" diff --git a/crates/ruff_python_formatter/src/expression/binary_like.rs b/crates/ruff_python_formatter/src/expression/binary_like.rs index 8e4ab0f93b..cc72f346d0 100644 --- a/crates/ruff_python_formatter/src/expression/binary_like.rs +++ b/crates/ruff_python_formatter/src/expression/binary_like.rs @@ -506,7 +506,12 @@ const fn is_simple_power_operand(expr: &Expr) -> bool { op: UnaryOp::Not, .. }) => false, Expr::Constant(ExprConstant { - value: Constant::Complex { .. } | Constant::Float(_) | Constant::Int(_), + value: + Constant::Complex { .. } + | Constant::Float(_) + | Constant::Int(_) + | Constant::None + | Constant::Bool(_), .. }) => true, Expr::Name(_) => true, diff --git a/crates/ruff_python_formatter/tests/snapshots/format@expression__binary_pow_spacing.py.snap b/crates/ruff_python_formatter/tests/snapshots/format@expression__binary_pow_spacing.py.snap new file mode 100644 index 0000000000..c22840f9f2 --- /dev/null +++ b/crates/ruff_python_formatter/tests/snapshots/format@expression__binary_pow_spacing.py.snap @@ -0,0 +1,34 @@ +--- +source: crates/ruff_python_formatter/tests/fixtures.rs +input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/binary_pow_spacing.py +--- +## Input +```py +# No spacing +5 ** 5 +5.0 ** 5.0 +1e5 ** 2e5 +True ** True +False ** False +None ** None + +# Space +"a" ** "b" +``` + +## Output +```py +# No spacing +5**5 +5.0**5.0 +1e5**2e5 +True**True +False**False +None**None + +# Space +"a" ** "b" +``` + + +