jgdv.structs.dkey._util.expander_stack

Type Aliases

ExpOpts

InstructionAlts

InstructionExpansions

InstructionList

Classes

DKeyExpanderStack

A Static class to control expansion.

InstructionFactory

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,
) <Unknown>[source]

really, keys with conv params should been built as a specialized registered type, to use an exp_final_hook

Parameters:
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:
Return type:

None

coerce_result(inst, root, opts) <Unknown>[source]

Coerce the expanded value accoring to source’s expansion type ctor

Parameters:
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:
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:
Return type:

jgdv.Maybe[jgdv.structs.dkey._util._interface.ExpInst_d]

extra_sources(chain, sources) <Unknown>[source]
Parameters:
Return type:

jgdv.structs.dkey._util._interface.SourceChain_d

finalise(inst, root, opts) <Unknown>[source]

A place for any remaining modifications of the result or fallback value

Parameters:
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:
Return type:

jgdv.Maybe[jgdv.structs.dkey._util._interface.ExpInst_d]

redirect(source, *sources, **kwargs) <Unknown>[source]
Parameters:
Return type:

list[jgdv.Maybe[jgdv.structs.dkey._util._interface.ExpInst_d]]

set_ctor(ctor) <Unknown>[source]

Dependency injection from DKey.__init_subclass__

Parameters:

ctor (type[jgdv.structs.dkey._interface.Key_p])

Return type:

None

_ctor: type[jgdv.structs.dkey._interface.Key_p]
_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:
Return type:

tuple[bool, bool]

_calc_recursion(
key,
val,
opts,
*,
decrement=True,
) <Unknown>[source]
Parameters:
Return type:

jgdv.Maybe[int]

build_chains(val, opts) <Unknown>[source]
Parameters:
Return type:

list[jgdv.structs.dkey._util._interface.ExpInstChain_d | jgdv.structs.dkey._util._interface.ExpInst_d]

build_inst(
val,
root,
opts,
*,
decrement=True,
) <Unknown>[source]
Parameters:
Return type:

jgdv.Maybe[jgdv.structs.dkey._util._interface.ExpInst_d]

build_single_chain(vals, root) <Unknown>[source]
Parameters:
Return type:

jgdv.structs.dkey._util._interface.ExpInstChain_d

lift_inst(
val,
root,
opts,
*,
decrement=False,
implicit=False,
) <Unknown>[source]
Parameters:
Return type:

jgdv.structs.dkey._util._interface.ExpInst_d

literal_inst(val) <Unknown>[source]
Parameters:

val (Any)

Return type:

jgdv.structs.dkey._util._interface.ExpInst_d

null_inst() <Unknown>[source]
Return type:

jgdv.structs.dkey._util._interface.ExpInst_d

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]]