Skip to content

Commit

Permalink
Tweak parser
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Aug 2, 2023
1 parent cd40f0a commit 0ab49ee
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
1 change: 0 additions & 1 deletion crates/ruff/src/checkers/ast/analyze/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,6 @@ pub(crate) fn expression(expr: &Expr, checker: &mut Checker) {
let location = expr.range();
match pyflakes::format::FormatSummary::try_from(val.as_ref()) {
Err(e) => {
println!("error: {}", e);
if checker.enabled(Rule::StringDotFormatInvalidFormat) {
checker.diagnostics.push(Diagnostic::new(
pyflakes::rules::StringDotFormatInvalidFormat {
Expand Down
1 change: 0 additions & 1 deletion crates/ruff/src/rules/pyflakes/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ impl TryFrom<&str> for FormatSummary {
};

let nested = FormatString::from_str(format_spec)?;
println!("nested: {:?}", nested);
for nested_part in nested.format_parts {
let FormatPart::Field { field_name, .. } = nested_part else {
continue;
Expand Down
21 changes: 12 additions & 9 deletions crates/ruff_python_literal/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,17 +284,20 @@ impl FormatSpec {
let (width, text) = parse_number(text)?;
let (grouping_option, text) = FormatGrouping::parse(text);
let (precision, text) = parse_precision(text)?;
let (format_type, new_text) = FormatType::parse(text);
match format_type {
None if new_text != text => {
let (format_type, _text) = if text.is_empty() {
(None, text)
} else {
// If there's any remaining text, we should yield a valid format type and consume it
// all.
let (format_type, text) = FormatType::parse(text);
if format_type.is_none() {
return Err(FormatSpecError::InvalidFormatType);
}
_ => (),
}

if !new_text.is_empty() {
return Err(FormatSpecError::InvalidFormatSpecifier);
}
if !text.is_empty() {
return Err(FormatSpecError::InvalidFormatSpecifier);
}
(format_type, text)
};

if zero && fill.is_none() {
fill.replace('0');
Expand Down

0 comments on commit 0ab49ee

Please sign in to comment.