Skip to content
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

PLE1307: false positive #8406

Closed
spaceone opened this issue Nov 1, 2023 · 1 comment · Fixed by #8407
Closed

PLE1307: false positive #8406

spaceone opened this issue Nov 1, 2023 · 1 comment · Fixed by #8407
Labels
bug Something isn't working

Comments

@spaceone
Copy link
Contributor

spaceone commented Nov 1, 2023

PLE1307: false positive:

$ cat x.py
print('[%c]' % ('x',))
print('[%c]' % 'x')
$ ruff x.py
x.py:1:7: PLE1307 Format type does not match argument type
x.py:2:7: PLE1307 Format type does not match argument type
Found 2 errors.
@zanieb
Copy link
Member

zanieb commented Nov 1, 2023

Thanks for the report. I dug into this a bit and the issue is that %c is an integer format type. Characters can be coerced to integers so they work at runtime, but Ruff's type analysis e.g. analyze::type_inference::PythonType does not support characters. I'm not sure how best to represent objects that can be both characters and strings in our type system so there's not a quick fix for this although it does seem easy enough to detect strings with a single item and special case them.

@zanieb zanieb added the bug Something isn't working label Nov 1, 2023
zanieb added a commit that referenced this issue Nov 2, 2023
…rs (#8407)

Closes #8406

---------

Co-authored-by: Dhruv Manilawala <dhruvmanila@gmail.com>
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 a pull request may close this issue.

2 participants