mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-28 23:43:53 +00:00
Treat display as a builtin in IPython (#8707)
## Summary `display` is a special-cased builtin in IPython. This PR adds it to the builtin namespace when analyzing IPython notebooks. Closes https://github.com/astral-sh/ruff/issues/8702.
This commit is contained in:
parent
2083352ae3
commit
4ac78d5725
13 changed files with 160 additions and 22 deletions
|
@ -1,7 +1,7 @@
|
|||
/// A list of all Python builtins.
|
||||
///
|
||||
/// Intended to be kept in sync with [`is_builtin`].
|
||||
pub const BUILTINS: &[&str] = &[
|
||||
/// Intended to be kept in sync with [`is_python_builtin`].
|
||||
pub const PYTHON_BUILTINS: &[&str] = &[
|
||||
"ArithmeticError",
|
||||
"AssertionError",
|
||||
"AttributeError",
|
||||
|
@ -161,6 +161,11 @@ pub const BUILTINS: &[&str] = &[
|
|||
"zip",
|
||||
];
|
||||
|
||||
/// A list of all builtins that are available in IPython.
|
||||
///
|
||||
/// Intended to be kept in sync with [`is_ipython_builtin`].
|
||||
pub const IPYTHON_BUILTINS: &[&str] = &["display"];
|
||||
|
||||
/// Globally defined names which are not attributes of the builtins module, or
|
||||
/// are only present on some platforms.
|
||||
pub const MAGIC_GLOBALS: &[&str] = &[
|
||||
|
@ -173,9 +178,9 @@ pub const MAGIC_GLOBALS: &[&str] = &[
|
|||
|
||||
/// Returns `true` if the given name is that of a Python builtin.
|
||||
///
|
||||
/// Intended to be kept in sync with [`BUILTINS`].
|
||||
pub fn is_builtin(name: &str) -> bool {
|
||||
// Constructed by converting the `BUILTINS` slice to a `match` expression.
|
||||
/// Intended to be kept in sync with [`PYTHON_BUILTINS`].
|
||||
pub fn is_python_builtin(name: &str) -> bool {
|
||||
// Constructed by converting the `PYTHON_BUILTINS` slice to a `match` expression.
|
||||
matches!(
|
||||
name,
|
||||
"ArithmeticError"
|
||||
|
@ -345,3 +350,11 @@ pub fn is_iterator(name: &str) -> bool {
|
|||
"enumerate" | "filter" | "map" | "reversed" | "zip" | "iter"
|
||||
)
|
||||
}
|
||||
|
||||
/// Returns `true` if the given name is that of an IPython builtin.
|
||||
///
|
||||
/// Intended to be kept in sync with [`IPYTHON_BUILTINS`].
|
||||
pub fn is_ipython_builtin(name: &str) -> bool {
|
||||
// Constructed by converting the `IPYTHON_BUILTINS` slice to a `match` expression.
|
||||
matches!(name, "display")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue