pynenc.trigger.arguments.result_filter

Result filters for trigger-based task executions.

This module defines filters for task results that leverage the existing argument filtering infrastructure. These filters determine if task results match certain criteria by adapting them to the argument filter format.

Module Contents

Classes

ResultFilterProtocol

Protocol defining the interface for result filters.

NoResultFilter

This will disable result filtering.

StaticResultFilter

Filters task results based on exact matching with an expected value.

CallableResultFilter

Filters task results using a custom callable function.

Functions

create_result_filter

Factory function to create the appropriate result filter based on the input type.

API

class pynenc.trigger.arguments.result_filter.ResultFilterProtocol[source]

Bases: typing.Protocol

Protocol defining the interface for result filters.

This protocol specifies the required methods that any result filter must implement, regardless of class hierarchy.

filter_id() str

Generate a unique ID for this argument filter.

The ID is based on the ID of the callable filter.

to_json(app: pynenc.app.Pynenc) str[source]

Serialize this argument filter to a JSON string.

Parameters:

app – Pynenc application instance for serializing complex arguments

Returns:

JSON string representation of this argument filter

filter_result(result: Any) bool[source]

Determine if a result value satisfies this filter.

Parameters:

result – The result value to check

Returns:

True if the result satisfies the filter criteria

class pynenc.trigger.arguments.result_filter.NoResultFilter[source]

Bases: pynenc.trigger.arguments.argument_filters.ArgumentFilter

This will disable result filtering.

filter_id() str
filter_arguments(arguments: dict[str, Any]) bool[source]
filter_result(result: Any) bool[source]
_to_json(app: pynenc.app.Pynenc) dict[str, Any][source]
classmethod _from_json(data: dict[str, Any], app: pynenc.app.Pynenc) pynenc.trigger.arguments.result_filter.NoResultFilter[source]
class pynenc.trigger.arguments.result_filter.StaticResultFilter(expected_result: Any)[source]

Bases: pynenc.trigger.arguments.argument_filters.StaticArgumentFilter

Filters task results based on exact matching with an expected value.

This filter adapts the StaticArgumentFilter to work with result values.

Initialization

Initialize with an expected result value.

Parameters:

expected_result – Result value that task results must match

classmethod _from_json(data: dict[str, Any], app: pynenc.app.Pynenc) pynenc.trigger.arguments.result_filter.StaticResultFilter[source]

Create a StaticResultFilter from parsed JSON data.

Parameters:
  • data – Dictionary with filter data

  • app – Pynenc application instance for deserializing complex arguments

Returns:

A new StaticResultFilter instance

filter_result(result: Any) bool[source]

Check if the task result matches the expected value.

Parameters:

result – The result to check

Returns:

True if the result matches the expected value, False otherwise

class pynenc.trigger.arguments.result_filter.CallableResultFilter(callable_filter: collections.abc.Callable[[Any], bool] | pynenc.trigger.arguments.arguments_common.SerializableCallable)[source]

Bases: pynenc.trigger.arguments.argument_filters.CallableArgumentFilter

Filters task results using a custom callable function.

This filter adapts the CallableArgumentFilter to work with result values.

Initialization

Initialize with a callable filter for results.

Parameters:

callable_filter – Function that takes a result and returns a boolean

abstractmethod filter_arguments(arguments: dict[str, Any]) bool[source]
filter_result(result: Any) bool[source]
pynenc.trigger.arguments.result_filter.create_result_filter(filter_spec: Any | collections.abc.Callable[[Any], bool]) pynenc.trigger.arguments.result_filter.ResultFilterProtocol[source]

Factory function to create the appropriate result filter based on the input type.

Parameters:

filter_spec – Either an expected result value or a callable function

Returns:

An instance of ArgumentFilter