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

Ignore builtins when detecting missing f-strings #9849

Merged
merged 1 commit into from
Feb 6, 2024
Merged

Conversation

charliermarsh
Copy link
Member

Summary

Reported on Discord: if the name maps to a builtin, it's not bound locally, so is very unlikely to be intended as an f-string expression.

@ThiefMaster
Copy link
Contributor

ThiefMaster commented Feb 6, 2024

Some real code to test against (I think in all 3 cases it was triggered because of builtins):

Errors with the current stable release:

[adrian@eluvian:~/dev/indico/py3/src:master $]> ruff check --select RUF027
indico/modules/events/management/program_codes.py:50:21: RUF027 Possible f-string without an `f` prefix
indico/util/mdx_latex.py:393:23: RUF027 Possible f-string without an `f` prefix
indico/web/forms/validators.py:350:36: RUF027 Possible f-string without an `f` prefix
indico/web/forms/validators.py:351:36: RUF027 Possible f-string without an `f` prefix
indico/web/forms/validators.py:353:36: RUF027 Possible f-string without an `f` prefix
indico/web/forms/validators.py:354:36: RUF027 Possible f-string without an `f` prefix
indico/web/forms/validators.py:356:29: RUF027 Possible f-string without an `f` prefix
Found 7 errors.
No fixes available (7 hidden fixes can be enabled with the `--unsafe-fixes` option).

@charliermarsh
Copy link
Member Author

I think we should also ignore ngettext calls as you mention, but this would've prevented those false positives 👍

Copy link
Contributor

github-actions bot commented Feb 6, 2024

ruff-ecosystem results

Linter (stable)

ℹ️ ecosystem check encountered linter errors. (no lint changes; 1 project error)

sphinx-doc/sphinx (error)

ruff failed
  Cause: Selection of unstable rules without the `--preview` flag is not allowed. Enable preview or remove selection of:
	- FURB113
	- FURB131
	- FURB132

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+0 -36 violations, +0 -0 fixes in 2 projects; 41 projects unchanged)

pandas-dev/pandas (+0 -2 violations, +0 -0 fixes)

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

- pandas/tests/indexes/base_class/test_formats.py:138:35: RUF027 Possible f-string without an `f` prefix
- pandas/tests/indexes/base_class/test_formats.py:141:16: RUF027 Possible f-string without an `f` prefix

zulip/zulip (+0 -34 violations, +0 -0 fixes)

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

- zerver/management/commands/edit_linkifiers.py:14:12: RUF027 Possible f-string without an `f` prefix
- zerver/migrations/0423_fix_email_gateway_attachment_owner.py:93:21: RUF027 Possible f-string without an `f` prefix
- zerver/openapi/curl_param_value_generators.py:281:9: RUF027 Possible f-string without an `f` prefix
- zerver/openapi/python_examples.py:454:25: RUF027 Possible f-string without an `f` prefix
- zerver/openapi/python_examples.py:469:25: RUF027 Possible f-string without an `f` prefix
- zerver/tests/test_audit_log.py:914:26: RUF027 Possible f-string without an `f` prefix
- zerver/tests/test_audit_log.py:974:29: RUF027 Possible f-string without an `f` prefix
- zerver/tests/test_event_system.py:762:29: RUF027 Possible f-string without an `f` prefix
- zerver/tests/test_events.py:2747:15: RUF027 Possible f-string without an `f` prefix
- zerver/tests/test_markdown.py:2506:24: RUF027 Possible f-string without an `f` prefix
- zerver/tests/test_markdown.py:2604:24: RUF027 Possible f-string without an `f` prefix
- zerver/tests/test_markdown.py:2892:24: RUF027 Possible f-string without an `f` prefix
- zerver/tests/test_markdown.py:2962:24: RUF027 Possible f-string without an `f` prefix
- zerver/tests/test_message_dict.py:246:24: RUF027 Possible f-string without an `f` prefix
- zerver/tests/test_realm_linkifiers.py:101:32: RUF027 Possible f-string without an `f` prefix
- zerver/tests/test_realm_linkifiers.py:134:32: RUF027 Possible f-string without an `f` prefix
- zerver/tests/test_realm_linkifiers.py:164:29: RUF027 Possible f-string without an `f` prefix
- zerver/tests/test_realm_linkifiers.py:180:29: RUF027 Possible f-string without an `f` prefix
- zerver/tests/test_realm_linkifiers.py:186:29: RUF027 Possible f-string without an `f` prefix
- zerver/tests/test_realm_linkifiers.py:203:29: RUF027 Possible f-string without an `f` prefix
- zerver/tests/test_realm_linkifiers.py:216:32: RUF027 Possible f-string without an `f` prefix
- zerver/tests/test_realm_linkifiers.py:24:29: RUF027 Possible f-string without an `f` prefix
- zerver/tests/test_realm_linkifiers.py:319:33: RUF027 Possible f-string without an `f` prefix
- zerver/tests/test_realm_linkifiers.py:323:33: RUF027 Possible f-string without an `f` prefix
- zerver/tests/test_realm_linkifiers.py:327:33: RUF027 Possible f-string without an `f` prefix
- zerver/tests/test_realm_linkifiers.py:37:48: RUF027 Possible f-string without an `f` prefix
- zerver/tests/test_realm_linkifiers.py:63:32: RUF027 Possible f-string without an `f` prefix
- zerver/tests/test_realm_linkifiers.py:69:32: RUF027 Possible f-string without an `f` prefix
- zerver/tests/test_realm_linkifiers.py:75:32: RUF027 Possible f-string without an `f` prefix
- zerver/tests/test_realm_linkifiers.py:82:13: RUF027 Possible f-string without an `f` prefix
- zerver/tests/test_realm_linkifiers.py:89:32: RUF027 Possible f-string without an `f` prefix
- zerver/tests/test_realm_linkifiers.py:95:32: RUF027 Possible f-string without an `f` prefix
- zilencer/management/commands/populate_db.py:832:17: RUF027 Possible f-string without an `f` prefix
- zilencer/management/commands/populate_db.py:838:17: RUF027 Possible f-string without an `f` prefix

Changes by rule (1 rules affected)

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

@charliermarsh
Copy link
Member Author

Ecosystem checks look like improvements to me.

Copy link
Contributor

@snowsignal snowsignal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! I'm really happy to see fewer false positives in the ecosystem check.

@charliermarsh charliermarsh merged commit a662c24 into main Feb 6, 2024
17 checks passed
@charliermarsh charliermarsh deleted the charlie/b branch February 6, 2024 04:49
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.

3 participants