-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix bug where PLE1307
was raised when formatting %c
with characters
#8407
Conversation
crates/ruff_linter/resources/test/fixtures/pylint/bad_string_format_type.py
Outdated
Show resolved
Hide resolved
|
ResolvedPythonType::Atom(atom) => { | ||
// Special case where `%c` allows single character strings to be formatted | ||
if format.format_char == 'c' { | ||
if let Expr::StringLiteral(string) = value { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this also be a byte string or fstring?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm good idea, I checked:
print("%c" % b"x") # Runtime error
print("%c" % f"x") # OK
I'm hesitant to support the format string though it's a weird use.
crates/ruff_linter/resources/test/fixtures/pylint/bad_string_format_type.py
Outdated
Show resolved
Hide resolved
Co-authored-by: Dhruv Manilawala <[email protected]>
Closes #8406