-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
RUF027 false negative on method calls #9857
Comments
It seems intentional. This is from the documentation explaining when the rule doesn't trigger.
@snowsignal can you help us understand the motivation behind it? |
What does a "parent expresssion of the literal" mean exactly? If it means it won't trigger on things like Shouldn't it only count if a method is called on the string itself? |
You're right, this rule only applies to the string itself, plus any parent expressions that the string is in. The example you gave is definitely something we should catch. Luckily, I think I have a good idea of why this is happening, and I'll try to make a fix for this soon. A parent expression of the literal would be something like |
…ethod calls (#9865) Fixes #9857. ## Summary Statements like `logging.info("Today it is: {day}")` will no longer be ignored by RUF027. As before, statements like `"Today it is: {day}".format(day="Tuesday")` will continue to be ignored. ## Test Plan The snapshot tests were expanded to include new cases. Additionally, the snapshot tests have been split in two to separate positive cases from negative cases.
…ethod calls (astral-sh#9865) Fixes astral-sh#9857. ## Summary Statements like `logging.info("Today it is: {day}")` will no longer be ignored by RUF027. As before, statements like `"Today it is: {day}".format(day="Tuesday")` will continue to be ignored. ## Test Plan The snapshot tests were expanded to include new cases. Additionally, the snapshot tests have been split in two to separate positive cases from negative cases.
From what I read in the original PR, the rule is meant to ignore string literals that have an immediate method call on them to avoid false positives, but from what I'm seeing, every line with a method call is completely ignored, even if the method is not invoked on the string itself. Is this intended behavior?
Sample code:
Invoked with:
Ruff version:
The text was updated successfully, but these errors were encountered: