Skip to main content

FnUnit

Struct FnUnit 

Source
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: bool

true 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 named TestCase or unittest.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: bool

true 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.

Auto Trait Implementations§

§

impl<'a> Freeze for FnUnit<'a>

§

impl<'a> RefUnwindSafe for FnUnit<'a>

§

impl<'a> Send for FnUnit<'a>

§

impl<'a> Sync for FnUnit<'a>

§

impl<'a> Unpin for FnUnit<'a>

§

impl<'a> UnsafeUnpin for FnUnit<'a>

§

impl<'a> UnwindSafe for FnUnit<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.