matrix_inverse.asyncoro module

Updated version of the MPyC Coroutine code file A few alterations have been made to ensure that type hinting can be applied properly

class matrix_inverse.asyncoro.YieldAwaitable(value)[source]

Bases: Generic[SomeType]

A class to be applied to values that need to be available to an outer function through the send method.

__await__()[source]

Trick to send the stored value to the outer MPyC coroutine wrapper when the Awaitable is awaited. The yield statement is caught by the outer wrapper by calling the send method of the coroutine it wraps around.

Return type:

Generator[TypeVar(SomeType), None, None]

Returns:

A generator yielding the stored value

value
matrix_inverse.asyncoro.mpc_coro(func, apply_program_counter_wrapper=True, ignore_type_hints=False)[source]

Decorator turning coroutine func into an MPyC coroutine. An MPyC coroutine is evaluated asynchronously, returning empty placeholders. The type of the placeholders is defined either by a return annotation of the form “-> expression” or by the first await expression in func. Return annotations can only be used for static types.

Parameters:
  • func (Callable[..., Coroutine[TypeVar(SecureElement), None, TypeVar(SecureElement)]]) – The async function to be wrapped

  • apply_program_counter_wrapper (bool) – A boolean value indicating whether a program counter wrapper should be applied

  • ignore_type_hints (bool) – A boolean indicating whether type annotations should be used by the code to deduce the type of the placeholder

Return type:

Callable[..., TypeVar(SecureElement)]

Returns:

A placeholder for which a result will automatically be set when the coroutine has finished running

matrix_inverse.asyncoro.mpc_coro_ignore(func)[source]

A wrapper for an MPC coroutine that ensures that the behaviour of the code is unaffected by the type annotations.

Parameters:

func (Callable[..., Coroutine[TypeVar(SecureElement), None, TypeVar(SecureElement)]]) – The async function to be wrapped

Return type:

Callable[..., TypeVar(SecureElement)]

Returns:

A placeholder for which a result will automatically be set when the coroutine has finished running

matrix_inverse.asyncoro.returnType(return_type, *dimensions)[source]

Define return type for MPyC coroutines and expose it to send calls in an outer method. It is used in first await expression in an MPyC coroutine. The YieldAwaitable assures that a call to await returnType passes the return type to the outer mpc_coro wrapper.

Parameters:
  • return_type – The Class type of the object(s) to be returned

  • dimensions – arguments that describe the dimensions of the nested list to be returned. If no dimensions are provided, a single placeholder is returned. If one or more dimension is provided, it returns a nested list containing objects. The nesting is done according to the dimensions provided.

Returns:

A placeholder or nested list of placeholders wrapped in a YieldAwaitable to expose the placeholder to an outer wrapper/coroutine.

matrix_inverse.asyncoro.returnType_no_wrap(return_type, *dimensions)[source]

Define return type for MPyC coroutines.

Parameters:
  • return_type – The Class type of the placeholder

  • dimensions – arguments that describe the dimensions of the nested list to be returned. If no dimensions are provided, a single placeholder is returned. If one or more dimension is provided, it returns a nested list containing objects. The nesting is done according to the dimensions provided.

Returns:

A placeholder or nested list of placeholders wrapped.