Slackbot
10/11/2023, 1:50 AMStefan Krawczyk
10/11/2023, 2:24 AMStefan Krawczyk
10/11/2023, 2:25 AMGireesh Ramji
10/11/2023, 2:28 AMStefan Krawczyk
10/11/2023, 2:38 AMStefan Krawczyk
10/11/2023, 2:41 AMElijah Ben Izzy
10/11/2023, 2:50 AMresolve
and inject
if you’re doing this at construction, not runtime. It would be a little ugly but if this is a common operation you can bury this in a custom decorator. Happy to share some code in a bit when I’m back at my desk!Elijah Ben Izzy
10/11/2023, 4:36 AM@function_modifiers.resolve(
when=ResolveAt.CONFIG_AVAILABLE,
decorate_with=lambda which_item: inject(item=source(which_item)) # whatever your logic is
)
def do_something(item: T) -> T:
return _do_something(item)
Then in the driver:
dr = driver.Driver({"hamilton.enable_power_user_mode" : True, "which_item" : 1})
...
So, as you’re well aware, this has the potential to get ugly with bespoke logic. One trick that I’ve observed people do, is to create a custom decorator:
def with_specified_input(available_items: List[str]):
return function_modifiers.resolve(
when=ResolveAt.CONFIG_AVAILABLE,
decorate_with=lambda which_item: inject(item=source(which_item)) # whatever your logic is
)
Note that this is one-time-use (we use the parameter, so it has to be called which_item
, but you can easily find a way to hack in your signature to have a custom element that you pass in.
This is part of a broader pattern of flexible decorators, which allows you to build some very powerful, domain-specific macros. Highly encourage you to keep a bank of the custom decorators you like, and even add some back to OS when you feel inclined!