Skip to content

Fix bug where PLE1307 was raised when formatting %c with characters#8407

Merged
zanieb merged 3 commits intomainfrom
zanie/ple-char
Nov 2, 2023
Merged

Fix bug where PLE1307 was raised when formatting %c with characters#8407
zanieb merged 3 commits intomainfrom
zanie/ple-char

Conversation

@zanieb
Copy link
Member

@zanieb zanieb commented Nov 1, 2023

Closes #8406

@github-actions
Copy link
Contributor

github-actions bot commented Nov 1, 2023

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@zanieb zanieb requested a review from charliermarsh November 1, 2023 16:44
@zanieb zanieb added the bug Something isn't working label Nov 1, 2023
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 {
Copy link
Member

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?

Copy link
Member Author

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.

Co-authored-by: Dhruv Manilawala <dhruvmanila@gmail.com>
@zanieb zanieb enabled auto-merge (squash) November 2, 2023 04:29
@zanieb zanieb merged commit a8a7230 into main Nov 2, 2023
@zanieb zanieb deleted the zanie/ple-char branch November 2, 2023 04:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PLE1307: false positive

3 participants