mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 02:12:22 +00:00
Avoid space around pow for None
, True
and False
(#8189)
This commit is contained in:
parent
8304c41714
commit
e36afc3324
3 changed files with 50 additions and 1 deletions
10
crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/binary_pow_spacing.py
vendored
Normal file
10
crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/binary_pow_spacing.py
vendored
Normal file
|
@ -0,0 +1,10 @@
|
|||
# No spacing
|
||||
5 ** 5
|
||||
5.0 ** 5.0
|
||||
1e5 ** 2e5
|
||||
True ** True
|
||||
False ** False
|
||||
None ** None
|
||||
|
||||
# Space
|
||||
"a" ** "b"
|
|
@ -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,
|
||||
|
|
|
@ -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"
|
||||
```
|
||||
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue