Skip to content

RUF027 no longer has false negatives with string literals inside of method calls#9865

Merged
snowsignal merged 2 commits intomainfrom
jane/linter/RUF027/method-call-fix
Feb 8, 2024
Merged

RUF027 no longer has false negatives with string literals inside of method calls#9865
snowsignal merged 2 commits intomainfrom
jane/linter/RUF027/method-call-fix

Conversation

@snowsignal
Copy link
Contributor

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.

@snowsignal snowsignal added the rule Implementing or modifying a lint rule label Feb 6, 2024
@snowsignal snowsignal changed the title RUF027 no longer has false negatives with string literals inside of method calls. RUF027 no longer has false negatives with string literals inside of method calls Feb 6, 2024
@github-actions
Copy link
Contributor

github-actions bot commented Feb 6, 2024

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+8 -0 violations, +0 -0 fixes in 3 projects; 40 projects unchanged)

RasaHQ/rasa (+4 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview

+ tests/core/nlg/test_response.py:372:9: RUF027 Possible f-string without an `f` prefix
+ tests/shared/core/test_slot_mappings.py:72:9: RUF027 Possible f-string without an `f` prefix
+ tests/shared/core/training_data/story_writer/test_yaml_story_writer.py:201:9: RUF027 Possible f-string without an `f` prefix
+ tests/test_model_training.py:922:9: RUF027 Possible f-string without an `f` prefix

ibis-project/ibis (+1 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview

+ ibis/expr/types/generic.py:752:37: RUF027 Possible f-string without an `f` prefix

rotki/rotki (+3 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview

+ rotkehlchen/db/dbhandler.py:2800:23: RUF027 Possible f-string without an `f` prefix
+ rotkehlchen/exchanges/bitpanda.py:275:47: RUF027 Possible f-string without an `f` prefix
+ rotkehlchen/exchanges/kraken.py:419:21: RUF027 Possible f-string without an `f` prefix

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
RUF027 8 8 0 0 0

@charliermarsh
Copy link
Member

The Rasa checks look like false positives (hard to avoid...), the Ibis check looks like a true positive (I think), the Pandas check looks like a false positive (maybe avoidable?), the Rotki checks look like they might be true positives.

@charliermarsh
Copy link
Member

Perhaps we could avoid the Pandas false positive by also ignoring calls with positional arguments that use the exact same name...

…ls that use variables which any method calls also use
@snowsignal
Copy link
Contributor Author

@charliermarsh I added some logic to ignore literals with matching regular arguments in addition to keyword arguments.

@codspeed-hq
Copy link

codspeed-hq bot commented Feb 7, 2024

CodSpeed Performance Report

Merging #9865 will improve performances by 11.53%

Comparing jane/linter/RUF027/method-call-fix (787ae4e) with main (daae28e)

Summary

⚡ 10 improvements
✅ 20 untouched benchmarks

Benchmarks breakdown

Benchmark main jane/linter/RUF027/method-call-fix Change
linter/all-rules[numpy/ctypeslib.py] 20.6 ms 18.9 ms +9.19%
linter/all-rules[large/dataset.py] 92.5 ms 82.9 ms +11.53%
linter/all-with-preview-rules[numpy/globals.py] 3.1 ms 2.9 ms +5.7%
linter/all-with-preview-rules[numpy/ctypeslib.py] 23.3 ms 21.5 ms +8.31%
linter/all-with-preview-rules[pydantic/types.py] 51 ms 47 ms +8.66%
linter/all-with-preview-rules[large/dataset.py] 105.1 ms 95.3 ms +10.23%
linter/all-with-preview-rules[unicode/pypinyin.py] 11.8 ms 11.2 ms +5.21%
linter/all-rules[numpy/globals.py] 2.8 ms 2.6 ms +6.35%
linter/all-rules[unicode/pypinyin.py] 10.8 ms 10.2 ms +5.8%
linter/all-rules[pydantic/types.py] 43.9 ms 39.6 ms +10.71%

@snowsignal snowsignal merged commit ad313b9 into main Feb 8, 2024
@snowsignal snowsignal deleted the jane/linter/RUF027/method-call-fix branch February 8, 2024 15:00
nkxxll pushed a commit to nkxxll/ruff that referenced this pull request Mar 10, 2024
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

rule Implementing or modifying a lint rule

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RUF027 false negative on method calls

3 participants