Skip to main content

FilterLogic

This class provides a trait for implementing complex filtering logic to determine whether specific items should be included or omitted during processing. It evaluates items based on explicit inclusion rules, default filter settings, and dynamic include/exclude sets or dictionaries provided at runtime. The class manages the recursive propagation of these filters, returning instructions on how to handle nested values.

Methods


explicit_include()

def explicit_include(
value: T
) - > bool

whether an index/key is explicitly included, this is combined with call-time include below

Parameters

NameTypeDescription
valueTThe index or key to check for explicit inclusion

Returns

TypeDescription
boolTrue if the value is explicitly marked for inclusion in the schema, False otherwise

default_filter()

def default_filter(
value: T
) - > bool

default decision on whether to include the item at a given index/key

Parameters

NameTypeDescription
valueTThe index or key to evaluate against the default filter logic

Returns

TypeDescription
boolThe default inclusion status for the item when no specific include/exclude rules apply

filter()

def filter(
py_key: impl IntoPyObject< 'py > + Copy,
int_key: T,
include: Option< &Bound< 'py, PyAny > >,
exclude: Option< &Bound< 'py, PyAny > >
) - > PyResult< NextFilters< 'py > >

Determines whether to omit or include a value at a specific index based on hierarchical include and exclude rules. It calculates the next level of filters to be passed down to nested objects.

Parameters

NameTypeDescription
py_keyimpl IntoPyObject< 'py > + CopyThe Python-compatible representation of the key used for lookups in include/exclude sets or dicts
int_keyTThe internal representation of the key used for schema-level explicit inclusion checks
includeOption< &Bound< 'py, PyAny > >An optional set or dictionary defining which keys should be included in the output
excludeOption< &Bound< 'py, PyAny > >An optional set or dictionary defining which keys should be excluded from the output

Returns

TypeDescription
PyResult< NextFilters< 'py > >Returns Ok(None) if the item should be omitted, or Ok(Some(IncludeExclude)) containing the filters for the next recursion level