[pyflakes] Improve error message for UndefinedName when a builtin was added in a newer version than specified in Ruff config (F821)#13293
Merged
AlexWaygood merged 3 commits intomainfrom Sep 10, 2024
Conversation
AlexWaygood
commented
Sep 9, 2024
Comment on lines
+39
to
+44
| "Undefined name `{name}`. \ | ||
| Added as a builtin in Python 3.{minor_version_builtin_added}; \ | ||
| consider specifying a newer `target-version` in your Ruff config." |
Member
Author
There was a problem hiding this comment.
This feels quite verbose but I'm not sure how to make it any shorter :/
pyflakes] Improve error message for UndefinedName when a builtin was added in a newer version than specified in Ruff config (F821))pyflakes] Improve error message for UndefinedName when a builtin was added in a newer version than specified in Ruff config (F821)
a0fce10 to
754651e
Compare
CodSpeed Performance ReportMerging #13293 will not alter performanceComparing Summary
|
Member
Author
Seems spurious to me |
Contributor
|
| code | total | + violation | - violation | + fix | - fix |
|---|---|---|---|---|---|
| F821 | 2 | 1 | 1 | 0 | 0 |
Linter (preview)
ℹ️ ecosystem check detected linter changes. (+1 -1 violations, +0 -0 fixes in 1 projects; 53 projects unchanged)
pytest-dev/pytest (+1 -1 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview
- testing/_py/test_local.py:22:45: F821 Undefined name `EncodingWarning` + testing/_py/test_local.py:22:45: F821 Undefined name `EncodingWarning`. Consider specifying `requires-python = ">= 3.10"` or `tool.ruff.target-version = "py310"` in your `pyproject.toml` file.
Changes by rule (1 rules affected)
| code | total | + violation | - violation | + fix | - fix |
|---|---|---|---|---|---|
| F821 | 2 | 1 | 1 | 0 | 0 |
… was added in a newer version than specified in Ruff config
754651e to
3145695
Compare
AlexWaygood
commented
Sep 9, 2024
Comment on lines
+41
to
53
| let tip = minor_version_builtin_added.map(|version_added| { | ||
| format!( | ||
| "Added as a builtin in Python 3.{version_added}; \ | ||
| consider specifying a newer `target-version` in your Ruff config." | ||
| ) | ||
| }); | ||
|
|
||
| if let Some(tip) = tip { | ||
| format!("Undefined name `{name}`. {tip}") | ||
| } else { | ||
| format!("Undefined name `{name}`") | ||
| } | ||
| } |
Member
Author
MichaReiser
reviewed
Sep 9, 2024
Member
MichaReiser
left a comment
There was a problem hiding this comment.
I'm probably too jetlag to understand the new function you added but maybe you can explain.
MichaReiser
approved these changes
Sep 10, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Fixes #13287.
This adds a new function to
ruff_python_stdlib::builtinsthat allows us to query if a symbol is a Python builtin that was added in a later version than the one that was specified in a user's Ruff configuration. This function allows us to provide a better error message if a builtin such asaiter,anextetc. is used, but the user either specified a lowtarget-versionin their Ruff configuration or didn't specify atarget-versionat all (which leads us to infer the default, currentlypy38).Test Plan
cargo test -p ruff_linter --lib