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

Method function_scope

crates/ruff_python_semantic/src/model.rs:2383–2390  ·  view source on GitHub ↗

Finds and returns the [`Scope`] corresponding to a given [`ast::StmtFunctionDef`]. This method searches all scopes created by a function definition, comparing the [`TextRange`] of the provided `function_def` with the range of the function associated with the scope.

(&self, function_def: &ast::StmtFunctionDef)

Source from the content-addressed store, hash-verified

2381 /// [`TextRange`] of the provided `function_def` with the range of the function
2382 /// associated with the scope.
2383 pub fn function_scope(&self, function_def: &ast::StmtFunctionDef) -> Option<&Scope<'_>> {
2384 self.scopes.iter().find(|scope| {
2385 let Some(function) = scope.kind.as_function() else {
2386 return false;
2387 };
2388 function.range() == function_def.range()
2389 })
2390 }
2391
2392 /// Return `true` if the model is in a `typing.Protocol` subclass or an abstract
2393 /// method.

Callers 2

unnecessary_assignFunction · 0.80

Calls 4

as_functionMethod · 0.80
findMethod · 0.45
iterMethod · 0.45
rangeMethod · 0.45

Tested by

no test coverage detected