front.scrap.binder_proposal¶
Naive stash of VF proposals for binding
-
class
front.scrap.binder_proposal.
Binder
(state: <function NewType.<locals>.new_type at 0x7f581fd819d0>, factory: Callable, container: type)[source]¶
-
front.scrap.binder_proposal.
mk_binder
(*identifiers: Union[Iterable[NewType.<locals>.new_type], str], state: NewType.<locals>.new_type, bound_val_factory=<class 'front.scrap.binder_proposal.BoundVal'>)[source]¶ - Parameters
identifiers –
bound_val_factory –
- Returns
>>> Binder = mk_binder('foo bar') >>> d = dict() >>> b = Binder(d)
We
b.foo
exists, but is not set.>>> b.foo ValueNotSet
So let’s set it:
>>> b.foo = 42 >>> b.foo 42
So
b.foo
is now set, but the real point is that this assignment was “registered” in the state we give theBinder
:>>> d {'foo': 42}
Wanna see that again?
>>> b.foo = "I'm bound" >>> b.foo "I'm bound" >>> d {'foo': "I'm bound"}
And same with
b.bar
:>>> b.bar ValueNotSet >>> b.bar = "me too" >>> b.bar 'me too' >>> d {'foo': "I'm bound", 'bar': 'me too'}
A
Binder
will also have some useful mapping methods that are linked to the underlyingstate
.>>> Binder = mk_binder('the', 'variables', 'I', 'want') >>> state = dict() >>> b = Binder(state) >>> list(b) [] >>> b.want # I see a want, but no value is set ValueNotSet >>> list(b) # list still gives me nothing [] >>> b.want = 42 # but if I set a value for want >>> list(b) # I see want in the list ['want'] >>> 'want' in b # I can do this too True >>> 'not_in_there' in b False >>> 'variables' in b # 'variables' not "there" because not set False