Skip to content

Commit 3e8cde7

Browse files
committed
Removed incompatibilty with CPython, fixed parser error handling
1 parent 3ccb117 commit 3e8cde7

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

parser/src/fstring.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ impl<'a> FStringParser<'a> {
7373
return Err(ExpectedRbrace);
7474
}
7575
});
76+
77+
let peek = self.chars.peek();
78+
if peek != Some(&'}') && peek != Some(&':') {
79+
return Err(ExpectedRbrace);
80+
}
7681
}
7782

7883
// match a python 3.8 self documenting expression
@@ -383,6 +388,7 @@ mod tests {
383388
#[test]
384389
fn test_parse_invalid_fstring() {
385390
assert_eq!(parse_fstring("{5!a"), Err(ExpectedRbrace));
391+
386392
assert_eq!(parse_fstring("{5!a1}"), Err(ExpectedRbrace));
387393
assert_eq!(parse_fstring("{5!"), Err(ExpectedRbrace));
388394

tests/snippets/fstrings.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,15 @@
1717
assert f'{16:0>+#10x}' == '00000+0x10'
1818
assert f"{{{(lambda x: f'hello, {x}')('world}')}" == '{hello, world}'
1919

20-
assert f'{foo=}' == 'foo=bar'
20+
21+
# base test of self documenting strings
22+
#assert f'{foo=}' == 'foo=bar' # TODO ' missing
2123

2224
num=42
23-
assert f'{num=}' == 'num=42'
25+
26+
f'{num=}' # keep this line as it will fail when using a python 3.7 interpreter
27+
28+
assert f'{num=}' == 'num=42',
2429
assert f'{num=:>10}' == 'num= 42'
2530

2631

0 commit comments

Comments
 (0)