mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-09 03:51:45 +00:00
Format numeric constants (#5972)
Co-authored-by: Micha Reiser <micha@reiser.io>
This commit is contained in:
parent
33196f1859
commit
dfa81b6fe0
6 changed files with 227 additions and 233 deletions
|
@ -1,118 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/py_36/numeric_literals.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
#!/usr/bin/env python3.6
|
||||
|
||||
x = 123456789
|
||||
x = 123456
|
||||
x = .1
|
||||
x = 1.
|
||||
x = 1E+1
|
||||
x = 1E-1
|
||||
x = 1.000_000_01
|
||||
x = 123456789.123456789
|
||||
x = 123456789.123456789E123456789
|
||||
x = 123456789E123456789
|
||||
x = 123456789J
|
||||
x = 123456789.123456789J
|
||||
x = 0XB1ACC
|
||||
x = 0B1011
|
||||
x = 0O777
|
||||
x = 0.000000006
|
||||
x = 10000
|
||||
x = 133333
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -2,19 +2,19 @@
|
||||
|
||||
x = 123456789
|
||||
x = 123456
|
||||
-x = 0.1
|
||||
-x = 1.0
|
||||
-x = 1e1
|
||||
-x = 1e-1
|
||||
+x = .1
|
||||
+x = 1.
|
||||
+x = 1E+1
|
||||
+x = 1E-1
|
||||
x = 1.000_000_01
|
||||
x = 123456789.123456789
|
||||
-x = 123456789.123456789e123456789
|
||||
-x = 123456789e123456789
|
||||
-x = 123456789j
|
||||
-x = 123456789.123456789j
|
||||
-x = 0xB1ACC
|
||||
-x = 0b1011
|
||||
-x = 0o777
|
||||
+x = 123456789.123456789E123456789
|
||||
+x = 123456789E123456789
|
||||
+x = 123456789J
|
||||
+x = 123456789.123456789J
|
||||
+x = 0XB1ACC
|
||||
+x = 0B1011
|
||||
+x = 0O777
|
||||
x = 0.000000006
|
||||
x = 10000
|
||||
x = 133333
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
#!/usr/bin/env python3.6
|
||||
|
||||
x = 123456789
|
||||
x = 123456
|
||||
x = .1
|
||||
x = 1.
|
||||
x = 1E+1
|
||||
x = 1E-1
|
||||
x = 1.000_000_01
|
||||
x = 123456789.123456789
|
||||
x = 123456789.123456789E123456789
|
||||
x = 123456789E123456789
|
||||
x = 123456789J
|
||||
x = 123456789.123456789J
|
||||
x = 0XB1ACC
|
||||
x = 0B1011
|
||||
x = 0O777
|
||||
x = 0.000000006
|
||||
x = 10000
|
||||
x = 133333
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
#!/usr/bin/env python3.6
|
||||
|
||||
x = 123456789
|
||||
x = 123456
|
||||
x = 0.1
|
||||
x = 1.0
|
||||
x = 1e1
|
||||
x = 1e-1
|
||||
x = 1.000_000_01
|
||||
x = 123456789.123456789
|
||||
x = 123456789.123456789e123456789
|
||||
x = 123456789e123456789
|
||||
x = 123456789j
|
||||
x = 123456789.123456789j
|
||||
x = 0xB1ACC
|
||||
x = 0b1011
|
||||
x = 0o777
|
||||
x = 0.000000006
|
||||
x = 10000
|
||||
x = 133333
|
||||
```
|
||||
|
||||
|
|
@ -1,72 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/py_36/numeric_literals_skip_underscores.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
#!/usr/bin/env python3.6
|
||||
|
||||
x = 123456789
|
||||
x = 1_2_3_4_5_6_7
|
||||
x = 1E+1
|
||||
x = 0xb1acc
|
||||
x = 0.00_00_006
|
||||
x = 12_34_567J
|
||||
x = .1_2
|
||||
x = 1_2.
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
x = 123456789
|
||||
x = 1_2_3_4_5_6_7
|
||||
-x = 1e1
|
||||
-x = 0xB1ACC
|
||||
+x = 1E+1
|
||||
+x = 0xb1acc
|
||||
x = 0.00_00_006
|
||||
-x = 12_34_567j
|
||||
-x = 0.1_2
|
||||
-x = 1_2.0
|
||||
+x = 12_34_567J
|
||||
+x = .1_2
|
||||
+x = 1_2.
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
#!/usr/bin/env python3.6
|
||||
|
||||
x = 123456789
|
||||
x = 1_2_3_4_5_6_7
|
||||
x = 1E+1
|
||||
x = 0xb1acc
|
||||
x = 0.00_00_006
|
||||
x = 12_34_567J
|
||||
x = .1_2
|
||||
x = 1_2.
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
#!/usr/bin/env python3.6
|
||||
|
||||
x = 123456789
|
||||
x = 1_2_3_4_5_6_7
|
||||
x = 1e1
|
||||
x = 0xB1ACC
|
||||
x = 0.00_00_006
|
||||
x = 12_34_567j
|
||||
x = 0.1_2
|
||||
x = 1_2.0
|
||||
```
|
||||
|
||||
|
|
@ -34,38 +34,21 @@ y = 100(no)
|
|||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,19 +1,19 @@
|
||||
x = (123456789).bit_count()
|
||||
x = (123456).__abs__()
|
||||
-x = (0.1).is_integer()
|
||||
-x = (1.0).imag
|
||||
-x = (1e1).imag
|
||||
-x = (1e-1).real
|
||||
+x = (.1).is_integer()
|
||||
+x = (1.).imag
|
||||
+x = (1E+1).imag
|
||||
+x = (1E-1).real
|
||||
x = (123456789.123456789).hex()
|
||||
-x = (123456789.123456789e123456789).real
|
||||
-x = (123456789e123456789).conjugate()
|
||||
-x = 123456789j.real
|
||||
@@ -8,10 +8,10 @@
|
||||
x = (123456789.123456789e123456789).real
|
||||
x = (123456789e123456789).conjugate()
|
||||
x = 123456789j.real
|
||||
-x = 123456789.123456789j.__add__(0b1011.bit_length())
|
||||
-x = 0xB1ACC.conjugate()
|
||||
-x = 0b1011.conjugate()
|
||||
-x = 0o777.real
|
||||
+x = (123456789.123456789E123456789).real
|
||||
+x = (123456789E123456789).conjugate()
|
||||
+x = 123456789J.real
|
||||
+x = 123456789.123456789J.__add__((0b1011).bit_length())
|
||||
+x = (0XB1ACC).conjugate()
|
||||
+x = (0B1011).conjugate()
|
||||
+x = (0O777).real
|
||||
+x = 123456789.123456789j.__add__((0b1011).bit_length())
|
||||
+x = (0xB1ACC).conjugate()
|
||||
+x = (0b1011).conjugate()
|
||||
+x = (0o777).real
|
||||
x = (0.000000006).hex()
|
||||
-x = -100.0000j
|
||||
+x = -100.0000J
|
||||
x = -100.0000j
|
||||
|
||||
if (10).real:
|
||||
...
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
@ -73,20 +56,20 @@ y = 100(no)
|
|||
```py
|
||||
x = (123456789).bit_count()
|
||||
x = (123456).__abs__()
|
||||
x = (.1).is_integer()
|
||||
x = (1.).imag
|
||||
x = (1E+1).imag
|
||||
x = (1E-1).real
|
||||
x = (0.1).is_integer()
|
||||
x = (1.0).imag
|
||||
x = (1e1).imag
|
||||
x = (1e-1).real
|
||||
x = (123456789.123456789).hex()
|
||||
x = (123456789.123456789E123456789).real
|
||||
x = (123456789E123456789).conjugate()
|
||||
x = 123456789J.real
|
||||
x = 123456789.123456789J.__add__((0b1011).bit_length())
|
||||
x = (0XB1ACC).conjugate()
|
||||
x = (0B1011).conjugate()
|
||||
x = (0O777).real
|
||||
x = (123456789.123456789e123456789).real
|
||||
x = (123456789e123456789).conjugate()
|
||||
x = 123456789j.real
|
||||
x = 123456789.123456789j.__add__((0b1011).bit_length())
|
||||
x = (0xB1ACC).conjugate()
|
||||
x = (0b1011).conjugate()
|
||||
x = (0o777).real
|
||||
x = (0.000000006).hex()
|
||||
x = -100.0000J
|
||||
x = -100.0000j
|
||||
|
||||
if (10).real:
|
||||
...
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue