Skip to content

Commit cba961e

Browse files
Apply suggestions from code review
Co-authored-by: Jeong YunWon <[email protected]>
1 parent 620115d commit cba961e

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

parser/src/fstring.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ impl<'a> FStringParser<'a> {
3434
// can be integrated better with the remainign code, but as a starting point ok
3535
// in general I would do here a tokenizing of the fstrings to omit this peeking.
3636
'!' if self.chars.peek() == Some(&'=') => {
37-
expression.push('!');
38-
expression.push('=');
37+
expression.push_str("!=");
3938
self.chars.next();
4039
}
4140

@@ -74,8 +73,8 @@ impl<'a> FStringParser<'a> {
7473
}
7574
});
7675

77-
let peek = self.chars.peek();
78-
if peek != Some(&'}') && peek != Some(&':') {
76+
if let Some(peek) = self.chars.peek() {
77+
if peek != '}' && peek != ':' {
7978
return Err(ExpectedRbrace);
8079
}
8180
}
@@ -197,11 +196,9 @@ impl<'a> FStringParser<'a> {
197196
}
198197
}
199198
}
200-
201199
' ' if !pred_expression_text.is_empty() => {
202200
trailing_seq.push(ch);
203201
}
204-
205202
_ => {
206203
expression.push(ch);
207204
}
@@ -388,7 +385,6 @@ mod tests {
388385
#[test]
389386
fn test_parse_invalid_fstring() {
390387
assert_eq!(parse_fstring("{5!a"), Err(ExpectedRbrace));
391-
392388
assert_eq!(parse_fstring("{5!a1}"), Err(ExpectedRbrace));
393389
assert_eq!(parse_fstring("{5!"), Err(ExpectedRbrace));
394390

tests/snippets/fstrings.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
import sys
55
import platform
66
if platform.python_implementation() == 'CPython':
7-
assert sys.version_info.major == 3, 'Incompatible Python Version, expected CPython 3.8 or later'
8-
assert sys.version_info.minor == 8, 'Incompatible Python Version, expected CPython 3.8 or later'
7+
assert sys.version_info >= (3, 8), 'Incompatible Python Version, expected CPython 3.8 or later'
98
elif platform.python_implementation == 'RustPython':
109
# ok
1110
pass
@@ -169,4 +168,4 @@ def assertEqual(self, a,b):
169168

170169
# self.assertEqual(f'X{x =}Y', 'Xx ='+x+'Y')
171170
# self.assertEqual(f'X{x= }Y', 'Xx= '+x+'Y')
172-
# self.assertEqual(f'X{x = }Y', 'Xx = '+x+'Y')
171+
# self.assertEqual(f'X{x = }Y', 'Xx = '+x+'Y')

0 commit comments

Comments
 (0)