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

Method function_scope

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

2410 /// [`TextRange`] of the provided `function_def` with the range of the function
2411 /// associated with the scope.
2412 pub fn function_scope(&self, function_def: &ast::StmtFunctionDef) -> Option<&Scope<'_>> {
2413 self.scopes.iter().find(|scope| {
2414 let Some(function) = scope.kind.as_function() else {
2415 return false;
2416 };
2417 function.range() == function_def.range()
2418 })
2419 }
2420
2421 /// Return `true` if the model is in a `typing.Protocol` subclass or an abstract
2422 /// 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