Sometimes, you have a bunch of arguments to functions such as the database connection object, and would prefer them not to be passed by an argument, but configured through Satella’s Environments themselves:
- class satella.coding.Context(parent: Context | None = None, **variables)¶
New layer of environment. Can have it’s own variables, or can hoist them onto the parent.
Warning
This is considered experimental. I just haven’t found out a good use case for it yet.
- does_exist(val: str) bool ¶
Does a given value exist on stack for this call of function?
- push_up(item: str, value=<object object>) None ¶
Advance current variable to the top of the card stack.
- Parameters:
item – variable name
value – if not given, current value of given variable will be taken
You can think of them as a stack of cards each carrying a set of variable names. The variable, if not present on the current card, will be checked upwards for parent of this card. Each thread, by default, gets a separate hierarchy. Removing a variable on one card will not affect it’s parent, however the variable will remain inaccessible for the duration of this context. Use them like this:
with Context() as ctxt:
ctxt.value = 55
with Context() as new_ctxt:
new_ctxt.value = 66
assert ctxt.value == 66
assert ctxt.value == 55