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

Method function_scope

crates/ruff_python_semantic/src/model.rs:2376–2383  ·  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

2374 /// [`TextRange`] of the provided `function_def` with the range of the function
2375 /// associated with the scope.
2376 pub fn function_scope(&self, function_def: &ast::StmtFunctionDef) -> Option<&Scope<'_>> {
2377 self.scopes.iter().find(|scope| {
2378 let Some(function) = scope.kind.as_function() else {
2379 return false;
2380 };
2381 function.range() == function_def.range()
2382 })
2383 }
2384
2385 /// Return `true` if the model is in a `typing.Protocol` subclass or an abstract
2386 /// 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