mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-29 13:24:57 +00:00
[pyflakes
] Fix false positives for __annotate__
(Py3.14+) and __warningregistry__
(F821
) (#20154)
## Summary Fixes #19970 --------- Co-authored-by: Alex Waygood <alex.waygood@gmail.com>
This commit is contained in:
parent
742f8a4ee6
commit
346842f003
7 changed files with 153 additions and 28 deletions
|
@ -20,9 +20,15 @@ pub const MAGIC_GLOBALS: &[&str] = &[
|
|||
"__annotations__",
|
||||
"__builtins__",
|
||||
"__cached__",
|
||||
"__warningregistry__",
|
||||
"__file__",
|
||||
];
|
||||
|
||||
/// Magic globals that are only available starting in specific Python versions.
|
||||
///
|
||||
/// `__annotate__` was introduced in Python 3.14.
|
||||
static PY314_PLUS_MAGIC_GLOBALS: &[&str] = &["__annotate__"];
|
||||
|
||||
static ALWAYS_AVAILABLE_BUILTINS: &[&str] = &[
|
||||
"ArithmeticError",
|
||||
"AssertionError",
|
||||
|
@ -216,6 +222,21 @@ pub fn python_builtins(minor_version: u8, is_notebook: bool) -> impl Iterator<It
|
|||
.copied()
|
||||
}
|
||||
|
||||
/// Return the list of magic globals for the given Python minor version.
|
||||
pub fn python_magic_globals(minor_version: u8) -> impl Iterator<Item = &'static str> {
|
||||
let py314_magic_globals = if minor_version >= 14 {
|
||||
Some(PY314_PLUS_MAGIC_GLOBALS)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
py314_magic_globals
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.chain(MAGIC_GLOBALS)
|
||||
.copied()
|
||||
}
|
||||
|
||||
/// Returns `true` if the given name is that of a Python builtin.
|
||||
///
|
||||
/// Intended to be kept in sync with [`python_builtins`].
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue