MCPcopy Create free account
hub / github.com/astral-sh/ruff / python_builtins

Function python_builtins

crates/ruff_python_stdlib/src/builtins.rs:201–237  ·  view source on GitHub ↗

Return the list of builtins for the given Python minor version. Intended to be kept in sync with [`is_python_builtin`].

(minor_version: u8, is_notebook: bool)

Source from the content-addressed store, hash-verified

199///
200/// Intended to be kept in sync with [`is_python_builtin`].
201pub fn python_builtins(minor_version: u8, is_notebook: bool) -> impl Iterator<Item = &'static str> {
202 let py310_builtins = if minor_version >= 10 {
203 Some(PY310_PLUS_BUILTINS)
204 } else {
205 None
206 };
207 let py311_builtins = if minor_version >= 11 {
208 Some(PY311_PLUS_BUILTINS)
209 } else {
210 None
211 };
212 let py313_builtins = if minor_version >= 13 {
213 Some(PY313_PLUS_BUILTINS)
214 } else {
215 None
216 };
217 let py315_builtins = if minor_version >= 15 {
218 Some(PY315_PLUS_BUILTINS)
219 } else {
220 None
221 };
222 let ipython_builtins = if is_notebook {
223 Some(IPYTHON_BUILTINS)
224 } else {
225 None
226 };
227
228 py310_builtins
229 .into_iter()
230 .chain(py311_builtins)
231 .chain(py313_builtins)
232 .chain(py315_builtins)
233 .chain(ipython_builtins)
234 .flatten()
235 .chain(ALWAYS_AVAILABLE_BUILTINS)
236 .copied()
237}
238
239/// Return the list of magic globals for the given Python minor version.
240pub fn python_magic_globals(minor_version: u8) -> impl Iterator<Item = &'static str> {

Callers 1

newMethod · 0.85

Calls 2

flattenMethod · 0.80
into_iterMethod · 0.45

Tested by

no test coverage detected