stubs.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
- stubs.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
[[ParamSpec
(P
, bound=None
)],Coroutine
[Any
,None
,TypeVar
(SecureElement
, bound=SecureObject
)]]) – The async function to be wrappedapply_program_counter_wrapper (
bool
) – A boolean value indicating whether a program counter wrapper should be appliedignore_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
[[ParamSpec
(P
, bound=None
)],TypeVar
(SecureElement
, bound=SecureObject
)]- Returns:
A placeholder for which a result will automatically be set when the coroutine has finished running
- stubs.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
[[ParamSpec
(P
, bound=None
)],Coroutine
[Any
,None
,TypeVar
(SecureElement
, bound=SecureObject
)]]) – The async function to be wrapped- Return type:
Callable
[[ParamSpec
(P
, bound=None
)],TypeVar
(SecureElement
, bound=SecureObject
)]- Returns:
A placeholder for which a result will automatically be set when the coroutine has finished running
- stubs.asyncoro.returnType(return_type, *dimensions, wrap=True)[source]¶
Define return type for MPyC coroutines and expose it to send calls in an outer method.
This function just delegates the call to the original definition of returnType in mpyc.asyncoro. Unfortunately, the type annotations are lost though in mpc.returnType due to the use of staticmethod which does not preserve overloads (mypy, v1.8.0). Alternatively, users could call mpyc.asyncoro.returnType directly but this seems counterintuitive and is hard to figure out. By exposing the method in tno.mpc.mpyc.stubs it is clearer that the standard mpc.returnType approach may not yield the expected results and we can provide this explanation.
- 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.
wrap (
bool
) – If True, wrap the result into an Awaitable object.
- Returns:
A placeholder or nested list of placeholders (wrapped in an awaitable object) to expose the placeholder to an outer wrapper/coroutine.