Skip to content

mf.as_is_callable#107

Merged
sbrodehl merged 1 commit intomasterfrom
as_is_callable
Jul 20, 2022
Merged

mf.as_is_callable#107
sbrodehl merged 1 commit intomasterfrom
as_is_callable

Conversation

@da-h
Copy link
Copy Markdown
Owner

@da-h da-h commented Jul 20, 2022

mf.as_is_callable

When defining default variables during register(), i.e. using register_helpers, it is possible to specify if callables are parsed to resolve variable chains using register_helpers({...}, parsefn=False).

This MR adds a small QoL-Alias to include the same functionality into the variable definition itself, i.e.
instead splitting into two calls:

mf.register_helpers({
   "var": lambda x: 42
})
mf.register_helpers({
   "instance": MyClass()
}, parsefn=False)

this feature allows to merge such calls into a single one:

mf.register_helpers({
   "var": lambda x: 42
   "instance": mf.as_is_callable(MyClass())
})

@da-h da-h requested a review from sbrodehl July 20, 2022 11:43
@da-h da-h force-pushed the as_is_callable branch 3 times, most recently from 3ee7fca to a645bd8 Compare July 20, 2022 12:39
Comment thread src/miniflask/miniflask.py
@da-h da-h force-pushed the as_is_callable branch 2 times, most recently from 919f743 to 95ed05a Compare July 20, 2022 19:46
@sbrodehl sbrodehl merged commit 99e07d1 into master Jul 20, 2022
@da-h
Copy link
Copy Markdown
Owner Author

da-h commented Jul 20, 2022

As a side-note (for future reference):

Another approach to tackle this would be to define it the other way round; i.e. to specify a callable that defines dependent variables using mf.dependent_variable.
I have decided against this, as it would require many code changes due to non-backwards-compatibility.

Nevertheless, this is something we could tackle in the future.
What do you think @sbrodehl ?

@da-h da-h deleted the as_is_callable branch July 20, 2022 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants