jgdv.structs.dkey._util.expander_stack
Type Aliases
Classes
A Static class to control expansion. |
|
Module Contents
- jgdv.structs.dkey._util.expander_stack.ExpOpts: TypeAlias = ExpAPI.ExpOpts
- jgdv.structs.dkey._util.expander_stack.InstructionAlts: TypeAlias = list[ExpInst_d]
- jgdv.structs.dkey._util.expander_stack.InstructionExpansions: TypeAlias = list[ExpInst_d]
- jgdv.structs.dkey._util.expander_stack.InstructionList: TypeAlias = list[InstructionAlts | ExpInst_d]
- class jgdv.structs.dkey._util.expander_stack.DKeyExpanderStack(*, ctor=None)[source]
A Static class to control expansion.
In order it does:
- pre-format the value to (A, coerceA,B, coerceB) - (lookup A) or (lookup B) or None - manipulates the retrieved value - potentially recurses on retrieved values - type coerces the value - runs a post-coercion hook - checks the type of the value to be returned
During the above, the hooks of Expandable_p will be called on the source, if they return nothing, the default hook implementation is used.
All of those steps are fallible. When one of them fails, then the expansion tries to return, in order:
- a fallback value passed into the expansion call - a fallback value stored on construction of the key - None
Redirection Rules:
- Hit || {test} => state[test=>blah] => blah - Soft Miss || {test} => state[test_=>blah] => {blah} - Hard Miss || {test} => state[...] => fallback or None
Indirect Keys act as:
- Indirect Soft Hit || {test_} => state[test_=>blah] => {blah} - Indirect Hard Hit || {test_} => state[test=>blah] => blah - Indirect Miss || {test_} => state[...] => {test_}
- Parameters:
ctor (jgdv.Maybe[type[jgdv.structs.dkey._interface.Key_p]])
- _coerce_result_by_conv_param(
- inst,
- conv,
- opts,
really, keys with conv params should been built as a specialized registered type, to use an exp_final_hook
- Parameters:
conv (str)
opts (ExpOpts)
- Return type:
jgdv.Maybe[jgdv.structs.dkey._util._interface.ExpInst_d]
- check_result(inst, root, opts) <Unknown>[source]
check the type of the expansion is correct, throw a type error otherwise
- Parameters:
inst (jgdv.Maybe[jgdv.structs.dkey._util._interface.ExpInst_d])
opts (ExpOpts)
- Return type:
None
- coerce_result(inst, root, opts) <Unknown>[source]
Coerce the expanded value accoring to source’s expansion type ctor
- Parameters:
inst (jgdv.Maybe[jgdv.structs.dkey._util._interface.ExpInst_d])
root (jgdv.Maybe[jgdv.structs.dkey._interface.Key_p])
opts (ExpOpts)
- Return type:
jgdv.Maybe[jgdv.structs.dkey._util._interface.ExpInst_d]
- do_lookup(target, sources, opts) <Unknown>[source]
customisable method for each key subtype Target is a list (L1) of lists (L2) of target tuples (T). For each L2, the first T that returns a value is added to the final result
- Parameters:
opts (ExpOpts)
- Return type:
jgdv.Maybe[jgdv.structs.dkey._util._interface.ExpInst_d]
- expand(key, *sources, **kwargs) <Unknown>[source]
The entry point for expanding a key
- Parameters:
sources (jgdv.structs.dkey._util._interface.SourceBases | jgdv.structs.dkey._util._interface.SourceChain_d)
kwargs (Any)
- Return type:
jgdv.Maybe[jgdv.structs.dkey._util._interface.ExpInst_d]
- finalise(inst, root, opts) <Unknown>[source]
A place for any remaining modifications of the result or fallback value
- Parameters:
opts (ExpOpts)
- Return type:
jgdv.Maybe[jgdv.structs.dkey._util._interface.ExpInst_d]
- flatten(values, root, opts) <Unknown>[source]
Flatten separate expansions into a single value
- Parameters:
values (list[jgdv.Maybe[jgdv.structs.dkey._util._interface.ExpInst_d]])
opts (ExpOpts)
- Return type:
jgdv.Maybe[jgdv.structs.dkey._util._interface.ExpInst_d]
- redirect(source, *sources, **kwargs) <Unknown>[source]
- Parameters:
source (jgdv.structs.dkey._interface.Key_p)
sources (jgdv.structs.dkey._util._interface.SourceBases)
kwargs (Any)
- Return type:
list[jgdv.Maybe[jgdv.structs.dkey._util._interface.ExpInst_d]]
- set_ctor(ctor) <Unknown>[source]
Dependency injection from DKey.__init_subclass__
- Parameters:
- Return type:
None
- _factory: ClassVar[InstructionFactory]
- class jgdv.structs.dkey._util.expander_stack.InstructionFactory(*, ctor=None)[source]
- Parameters:
ctor (jgdv.Maybe[type[jgdv.structs.dkey._interface.Key_p]])
- _calc_lift(val, opts) <Unknown>[source]
- Parameters:
val (jgdv.Maybe[jgdv.structs.dkey._util._interface.ExpInst_d])
opts (ExpOpts)
- Return type:
- _calc_recursion(
- key,
- val,
- opts,
- *,
- decrement=True,
- Parameters:
key (jgdv.Maybe[jgdv.structs.dkey._interface.Key_p])
val (jgdv.Maybe[jgdv.structs.dkey._util._interface.ExpInst_d])
opts (ExpOpts)
decrement (bool)
- Return type:
jgdv.Maybe[int]
- build_chains(val, opts) <Unknown>[source]
- Parameters:
opts (ExpOpts)
- Return type:
list[jgdv.structs.dkey._util._interface.ExpInstChain_d | jgdv.structs.dkey._util._interface.ExpInst_d]
- build_inst(
- val,
- root,
- opts,
- *,
- decrement=True,
- Parameters:
val (jgdv.Maybe)
root (jgdv.Maybe[jgdv.structs.dkey._util._interface.ExpInst_d])
opts (ExpOpts)
decrement (bool)
- Return type:
jgdv.Maybe[jgdv.structs.dkey._util._interface.ExpInst_d]
- build_single_chain(vals, root) <Unknown>[source]
- Parameters:
vals (list[jgdv.Maybe[jgdv.structs.dkey._util._interface.ExpInst_d]])
root (DKey)
- Return type:
- lift_inst(
- val,
- root,
- opts,
- *,
- decrement=False,
- implicit=False,
- Parameters:
val (str)
root (jgdv.Maybe[jgdv.structs.dkey._util._interface.ExpInst_d])
opts (ExpOpts)
decrement (bool)
implicit (bool)
- Return type:
- set_ctor(ctor) <Unknown>[source]
- Parameters:
ctor (jgdv.Maybe[type[jgdv.structs.dkey._interface.Key_p]])
- Return type:
None
- _ctor: jgdv.Maybe[type[jgdv.structs.dkey._interface.Key_p]]