-
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
[pyflakes
] Improve error message for UndefinedName
when a builtin was added in a newer version than specified in Ruff config (F821
)
#13293
Conversation
"Undefined name `{name}`. \ | ||
Added as a builtin in Python 3.{minor_version_builtin_added}; \ | ||
consider specifying a newer `target-version` in your Ruff config." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
|
Seems spurious to me |
|
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
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}`") | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm probably too jetlag to understand the new function you added but maybe you can explain.
Summary
Fixes #13287.
This adds a new function to
ruff_python_stdlib::builtins
that 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
,anext
etc. is used, but the user either specified a lowtarget-version
in their Ruff configuration or didn't specify atarget-version
at all (which leads us to infer the default, currentlypy38
).Test Plan
cargo test -p ruff_linter --lib