Skip to content

Commit 0ab49ee

Browse files
committed
Tweak parser
1 parent cd40f0a commit 0ab49ee

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

crates/ruff/src/checkers/ast/analyze/expression.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,6 @@ pub(crate) fn expression(expr: &Expr, checker: &mut Checker) {
372372
let location = expr.range();
373373
match pyflakes::format::FormatSummary::try_from(val.as_ref()) {
374374
Err(e) => {
375-
println!("error: {}", e);
376375
if checker.enabled(Rule::StringDotFormatInvalidFormat) {
377376
checker.diagnostics.push(Diagnostic::new(
378377
pyflakes::rules::StringDotFormatInvalidFormat {

crates/ruff/src/rules/pyflakes/format.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ impl TryFrom<&str> for FormatSummary {
5656
};
5757

5858
let nested = FormatString::from_str(format_spec)?;
59-
println!("nested: {:?}", nested);
6059
for nested_part in nested.format_parts {
6160
let FormatPart::Field { field_name, .. } = nested_part else {
6261
continue;

crates/ruff_python_literal/src/format.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -284,17 +284,20 @@ impl FormatSpec {
284284
let (width, text) = parse_number(text)?;
285285
let (grouping_option, text) = FormatGrouping::parse(text);
286286
let (precision, text) = parse_precision(text)?;
287-
let (format_type, new_text) = FormatType::parse(text);
288-
match format_type {
289-
None if new_text != text => {
287+
let (format_type, _text) = if text.is_empty() {
288+
(None, text)
289+
} else {
290+
// If there's any remaining text, we should yield a valid format type and consume it
291+
// all.
292+
let (format_type, text) = FormatType::parse(text);
293+
if format_type.is_none() {
290294
return Err(FormatSpecError::InvalidFormatType);
291295
}
292-
_ => (),
293-
}
294-
295-
if !new_text.is_empty() {
296-
return Err(FormatSpecError::InvalidFormatSpecifier);
297-
}
296+
if !text.is_empty() {
297+
return Err(FormatSpecError::InvalidFormatSpecifier);
298+
}
299+
(format_type, text)
300+
};
298301

299302
if zero && fill.is_none() {
300303
fill.replace('0');

0 commit comments

Comments
 (0)