Skip to content

Rule duplication F509 and PLE1300 #11403

@dhruvmanila

Description

@dhruvmanila

Both rules check for invalid format character in % format style string.

The implementation is almost the same:

F509

match pyflakes::cformat::CFormatSummary::try_from(value.to_str()) {
Err(CFormatError {
typ: CFormatErrorType::UnsupportedFormatChar(c),
..
}) => {
if checker.enabled(Rule::PercentFormatUnsupportedFormatCharacter) {
checker.diagnostics.push(Diagnostic::new(
pyflakes::rules::PercentFormatUnsupportedFormatCharacter {
char: c,
},
location,
));
}
}

PLE1300

// Parse the format string (e.g. `"%s"`) into a list of `PercentFormat`.
if let Err(format_error) = CFormatString::from_str(string) {
if let CFormatErrorType::UnsupportedFormatChar(format_char) = format_error.typ {
checker.diagnostics.push(Diagnostic::new(
BadStringFormatCharacter { format_char },
expr.range(),
));
}
};

There's one difference which can be noticed when an implicitly concatenated string is used. F509 looks at the concatenated string while PLE1300 looks at each part of an implicitly concatenated string. Refer to https://play.ruff.rs/6efd9945-2a3b-43e4-b9b7-a8d041b98318.

Reference:

Metadata

Metadata

Assignees

No one assigned

    Labels

    ruleImplementing or modifying a lint rule

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions