Skip to content

Commit 51b6571

Browse files
author
Charles Marsh
committed
Fix f-string regression
1 parent 2345bc8 commit 51b6571

13 files changed

Lines changed: 37 additions & 24 deletions

‎parser/src/fstring.rs‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::{
44
error::{FStringError, FStringErrorType, ParseError},
55
parser::parse_expression,
66
};
7+
use itertools::Itertools;
78
use std::{iter, mem, str};
89

910
struct FStringParser<'a> {
@@ -105,13 +106,16 @@ impl<'a> FStringParser<'a> {
105106
nested -= 1;
106107
if nested == 0 {
107108
formatted_value_piece.push(next);
108-
spec_constructor.extend(
109-
FStringParser::new(
110-
&format!("{{{}}}", formatted_value_piece),
111-
Location::default(),
112-
&self.recurse_lvl + 1,
113-
)
114-
.parse()?,
109+
let values = FStringParser::new(
110+
&formatted_value_piece,
111+
Location::default(),
112+
&self.recurse_lvl + 1,
113+
)
114+
.parse()?;
115+
spec_constructor.push(values
116+
.into_iter()
117+
.exactly_one()
118+
.expect("Expected formatted value to produce exactly one expression.")
115119
);
116120
formatted_value_piece.clear();
117121
} else {

‎parser/src/snapshots/rustpython_parser__fstring__tests__fstring_parse_selfdocumenting_base.snap‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
source: parser/src/fstring.rs
2+
source: compiler/parser/src/fstring.rs
33
expression: parse_ast
44
---
55
[

‎parser/src/snapshots/rustpython_parser__fstring__tests__fstring_parse_selfdocumenting_base_more.snap‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
source: parser/src/fstring.rs
2+
source: compiler/parser/src/fstring.rs
33
expression: parse_ast
44
---
55
[

‎parser/src/snapshots/rustpython_parser__fstring__tests__fstring_parse_selfdocumenting_format.snap‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
source: parser/src/fstring.rs
2+
source: compiler/parser/src/fstring.rs
33
expression: parse_ast
44
---
55
[
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
source: parser/src/fstring.rs
2+
source: compiler/parser/src/fstring.rs
33
expression: "parse_fstring(\"\").unwrap()"
44
---
55
[]

‎parser/src/snapshots/rustpython_parser__fstring__tests__parse_fstring.snap‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
source: parser/src/fstring.rs
2+
source: compiler/parser/src/fstring.rs
33
expression: parse_ast
44
---
55
[

‎parser/src/snapshots/rustpython_parser__fstring__tests__parse_fstring_equals.snap‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
source: parser/src/fstring.rs
2+
source: compiler/parser/src/fstring.rs
33
expression: parse_ast
44
---
55
[

‎parser/src/snapshots/rustpython_parser__fstring__tests__parse_fstring_nested_spec.snap‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
source: parser/src/fstring.rs
2+
source: compiler/parser/src/fstring.rs
33
expression: parse_ast
44
---
55
[
@@ -37,11 +37,20 @@ expression: parse_ast
3737
column: 0,
3838
},
3939
custom: (),
40-
node: Constant {
41-
value: Str(
42-
"{ spec}",
43-
),
44-
kind: None,
40+
node: FormattedValue {
41+
value: Located {
42+
location: Location {
43+
row: 1,
44+
column: 3,
45+
},
46+
custom: (),
47+
node: Name {
48+
id: "spec",
49+
ctx: Load,
50+
},
51+
},
52+
conversion: 0,
53+
format_spec: None,
4554
},
4655
},
4756
],

‎parser/src/snapshots/rustpython_parser__fstring__tests__parse_fstring_not_equals.snap‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
source: parser/src/fstring.rs
2+
source: compiler/parser/src/fstring.rs
33
expression: parse_ast
44
---
55
[

‎parser/src/snapshots/rustpython_parser__fstring__tests__parse_fstring_not_nested_spec.snap‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
source: parser/src/fstring.rs
2+
source: compiler/parser/src/fstring.rs
33
expression: parse_ast
44
---
55
[

0 commit comments

Comments
 (0)