Alexander Cai
06/26/2024, 7:57 AMconfig
options available as metadata anywhere on the function? Specifically, I'd like to check: For each function in a module, get the list of @config.when_in(...)
values as well as the keys.Elijah Ben Izzy
06/26/2024, 2:19 PMAlexander Cai
06/26/2024, 4:15 PMElijah Ben Izzy
06/26/2024, 4:21 PM@config.when(…)
, the lifecycle step is resolve
meaning that the decorated function is resolve
4. This can give you the optional/required config
Here’s a quick illustration:
In [1]: from hamilton.function_modifiers import config
In [2]: @config.when(foo="bar")
...: def a() -> int:
...: return 1
In [4]: a.resolve
Out[4]: [<hamilton.function_modifiers.configuration.config at 0x14db715d0>]
In [5]: a.resolve[0]
Out[5]: <hamilton.function_modifiers.configuration.config at 0x14db715d0>
In [8]: a.resolve[0].required_config()
Out[8]: []
In [9]: a.resolve[0].optional_config()
Out[9]: {'foo': None}
This is all fairly internal APIs, however, and doesn’t have the data you want (the values)Elijah Ben Izzy
06/26/2024, 4:25 PM@my_config_when(foo="bar")
def a() -> int:
return 1
assert a.__config == {"foo" : "bar"}
def my_config_when(**config_vars):
def wrapper(fn):
setattr(fn, "__config", config_vars)
return config.when(**config_vars)(fn)
return wrapper
Alexander Cai
06/26/2024, 4:55 PMElijah Ben Izzy
06/26/2024, 4:59 PM