pub struct FnUnit<'a> {
pub symbol: String,
pub line: usize,
pub col: usize,
pub is_async: bool,
pub is_test_unit: bool,
pub is_module_level: bool,
pub body: FnBody<'a>,
pub params: &'a Parameters<'a>,
pub decorators: &'a [Decorator<'a>],
pub returns: Option<&'a Annotation<'a>>,
}Expand description
A single function-shaped scope collected from the source.
line and col are 1-based (char column), matching core::Hotspot.
Borrows the body, parameters, and decorators from the parsed Module; valid
only within the single borrowed collect-then-analyze pass.
Fields§
§symbol: String§line: usize§col: usize§is_async: bool§is_test_unit: booltrue when this unit should be treated as test code for the purpose of
source-based skipping (see PythonFrontend::analyze):
- a
test_*-named top-level or nested function, OR - a method whose enclosing class name starts with
Test, OR - a method whose enclosing class subclasses
unittest.TestCase(base namedTestCaseorunittest.TestCase).
Lambdas are never test units. This flag is set at collection time when
the class context is available; PythonFrontend::analyze checks it.
is_module_level: booltrue ONLY for a def/async def directly at the module top level.
false for methods (inside a ClassDef), nested defs (inside another def),
lambdas, and the synthetic <module> unit.
This is the never-false-resolve guard for canonical_path: Python
FnUnit.symbol is the BARE name (a method def write has symbol "write"),
so without this flag a method write would get canonical_path = [pkg,util,write]
and a from pkg.util import write call could false-resolve to the method.
Only module-level defs are importable as module.<name>.
body: FnBody<'a>The function body (suite or lambda expression) to walk for own-body effects.
params: &'a Parameters<'a>The unit’s own parameters — their default expressions are charged to it.
decorators: &'a [Decorator<'a>]The unit’s own decorators — their expressions are charged to it (a lambda
has none, so this is empty for lambdas).
returns: Option<&'a Annotation<'a>>The unit’s return annotation (-> T), if any. Used by coverage as the
return slot. None for lambdas and for defs without a return annotation.