Skip to content

Commit cc84b4f

Browse files
committed
move unstable tests to preview file, finish preview gating
1 parent 087387d commit cc84b4f

6 files changed

Lines changed: 118 additions & 114 deletions

File tree

crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/lambda.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -142,32 +142,13 @@ def f(
142142
x
143143
)
144144

145-
(
146-
lambda
147-
# comment 1
148-
*
149-
# comment 2
150-
x,
151-
**y:
152-
# comment 3
153-
x
154-
)
155-
156145
(
157146
lambda # comment 1
158147
* # comment 2
159148
x: # comment 3
160149
x
161150
)
162151

163-
(
164-
lambda # comment 1
165-
* # comment 2
166-
x,
167-
y: # comment 3
168-
x
169-
)
170-
171152
lambda *x\
172153
:x
173154

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[
2+
{
3+
"preview": "enabled"
4+
}
5+
]
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""
2+
Test cases from lambda.py that cause an instability in the stable
3+
implementation but that are handled by the preview `indent_lambda_parameters`
4+
version.
5+
"""
6+
7+
(
8+
lambda
9+
# comment 1
10+
*
11+
# comment 2
12+
x,
13+
**y:
14+
# comment 3
15+
x
16+
)
17+
18+
(
19+
lambda # comment 1
20+
* # comment 2
21+
x,
22+
y: # comment 3
23+
x
24+
)

crates/ruff_python_formatter/src/other/parameters.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use crate::comments::{
1010
use crate::context::{NodeLevel, WithNodeLevel};
1111
use crate::expression::parentheses::empty_parenthesized;
1212
use crate::prelude::*;
13+
use crate::preview::is_indent_lambda_parameters_enabled;
1314

1415
#[derive(Debug, Copy, Clone, Eq, PartialEq, Default)]
1516
pub enum ParametersParentheses {
@@ -241,7 +242,11 @@ impl FormatNodeRule<Parameters> for FormatParameters {
241242
let num_parameters = item.len();
242243

243244
if self.parentheses == ParametersParentheses::Never {
244-
write!(f, [format_inner, dangling_comments(dangling)])
245+
if is_indent_lambda_parameters_enabled(f.context()) {
246+
write!(f, [format_inner, dangling_comments(dangling)])
247+
} else {
248+
write!(f, [group(&format_inner), dangling_comments(dangling)])
249+
}
245250
} else if num_parameters == 0 {
246251
let mut f = WithNodeLevel::new(NodeLevel::ParenthesizedExpression, f);
247252
// No parameters, format any dangling comments between `()`

crates/ruff_python_formatter/tests/snapshots/format@expression__lambda.py.snap

Lines changed: 8 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -148,32 +148,13 @@ lambda a, /, c: a
148148
x
149149
)
150150
151-
(
152-
lambda
153-
# comment 1
154-
*
155-
# comment 2
156-
x,
157-
**y:
158-
# comment 3
159-
x
160-
)
161-
162151
(
163152
lambda # comment 1
164153
* # comment 2
165154
x: # comment 3
166155
x
167156
)
168157
169-
(
170-
lambda # comment 1
171-
* # comment 2
172-
x,
173-
y: # comment 3
174-
x
175-
)
176-
177158
lambda *x\
178159
:x
179160
@@ -486,8 +467,7 @@ lambda a, /, c: a
486467
(
487468
lambda
488469
# comment
489-
*x,
490-
**y: x
470+
*x, **y: x
491471
)
492472
493473
(
@@ -499,31 +479,13 @@ lambda a, /, c: a
499479
x
500480
)
501481
502-
(
503-
lambda
504-
# comment 1
505-
# comment 2
506-
*x,
507-
**y:
508-
# comment 3
509-
x
510-
)
511-
512482
(
513483
lambda # comment 1
514484
# comment 2
515485
*x: # comment 3
516486
x
517487
)
518488
519-
(
520-
lambda # comment 1
521-
# comment 2
522-
*x,
523-
y: # comment 3
524-
x
525-
)
526-
527489
lambda *x: x
528490
529491
(
@@ -755,7 +717,7 @@ def a():
755717
):
756718
pass
757719
758-
@@ -122,48 +106,54 @@
720+
@@ -122,29 +106,34 @@
759721
760722
(
761723
lambda
@@ -769,8 +731,7 @@ def a():
769731
(
770732
lambda
771733
- # comment
772-
- *x,
773-
- **y: x
734+
- *x, **y: x
774735
+ # comment
775736
+ *x,
776737
+ **y
@@ -790,21 +751,6 @@ def a():
790751
x
791752
)
792753
793-
(
794-
lambda
795-
- # comment 1
796-
- # comment 2
797-
- *x,
798-
- **y:
799-
+ # comment 1
800-
+ # comment 2
801-
+ *x,
802-
+ **y
803-
+ :
804-
# comment 3
805-
x
806-
)
807-
808754
(
809755
lambda # comment 1
810756
- # comment 2
@@ -815,19 +761,7 @@ def a():
815761
x
816762
)
817763
818-
(
819-
lambda # comment 1
820-
- # comment 2
821-
- *x,
822-
- y: # comment 3
823-
+ # comment 2
824-
+ *x,
825-
+ y
826-
+ : # comment 3
827-
x
828-
)
829-
830-
@@ -171,8 +161,9 @@
764+
@@ -152,8 +141,9 @@
831765
832766
(
833767
lambda
@@ -839,7 +773,7 @@ def a():
839773
)
840774
841775
lambda: ( # comment
842-
@@ -210,8 +201,9 @@
776+
@@ -191,8 +181,9 @@
843777
844778
(
845779
lambda # 1
@@ -851,7 +785,7 @@ def a():
851785
# 4
852786
# 5
853787
# 6
854-
@@ -220,83 +212,94 @@
788+
@@ -201,83 +192,94 @@
855789
856790
(
857791
lambda # 1
@@ -1009,7 +943,7 @@ def a():
1009943
# Trailing
1010944
1011945
lambda self, araa, kkkwargs=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
1012-
@@ -310,9 +313,11 @@
946+
@@ -291,9 +293,11 @@
1013947
c,
1014948
d,
1015949
e,
@@ -1024,7 +958,7 @@ def a():
1024958
)
1025959
1026960
1027-
@@ -321,14 +326,16 @@
961+
@@ -302,14 +306,16 @@
1028962
c,
1029963
d,
1030964
e,
@@ -1200,17 +1134,6 @@ lambda a, /, c: a
12001134
x
12011135
)
12021136
1203-
(
1204-
lambda
1205-
# comment 1
1206-
# comment 2
1207-
*x,
1208-
**y
1209-
:
1210-
# comment 3
1211-
x
1212-
)
1213-
12141137
(
12151138
lambda # comment 1
12161139
# comment 2
@@ -1219,15 +1142,6 @@ lambda a, /, c: a
12191142
x
12201143
)
12211144
1222-
(
1223-
lambda # comment 1
1224-
# comment 2
1225-
*x,
1226-
y
1227-
: # comment 3
1228-
x
1229-
)
1230-
12311145
lambda *x: x
12321146
12331147
(
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
---
2+
source: crates/ruff_python_formatter/tests/fixtures.rs
3+
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/lambda_preview.py
4+
---
5+
## Input
6+
```python
7+
"""
8+
Test cases from lambda.py that cause an instability in the stable
9+
implementation but that are handled by the preview `indent_lambda_parameters`
10+
version.
11+
"""
12+
13+
(
14+
lambda
15+
# comment 1
16+
*
17+
# comment 2
18+
x,
19+
**y:
20+
# comment 3
21+
x
22+
)
23+
24+
(
25+
lambda # comment 1
26+
* # comment 2
27+
x,
28+
y: # comment 3
29+
x
30+
)
31+
```
32+
33+
## Outputs
34+
### Output 1
35+
```
36+
indent-style = space
37+
line-width = 88
38+
indent-width = 4
39+
quote-style = Double
40+
line-ending = LineFeed
41+
magic-trailing-comma = Respect
42+
docstring-code = Disabled
43+
docstring-code-line-width = "dynamic"
44+
preview = Enabled
45+
target_version = 3.10
46+
source_type = Python
47+
```
48+
49+
```python
50+
"""
51+
Test cases from lambda.py that cause an instability in the stable
52+
implementation but that are handled by the preview `indent_lambda_parameters`
53+
version.
54+
"""
55+
56+
(
57+
lambda
58+
# comment 1
59+
# comment 2
60+
*x,
61+
**y
62+
:
63+
# comment 3
64+
x
65+
)
66+
67+
(
68+
lambda # comment 1
69+
# comment 2
70+
*x,
71+
y
72+
: # comment 3
73+
x
74+
)
75+
```

0 commit comments

Comments
 (0)