This message was deleted.
# hamilton-help
s
This message was deleted.
e
Hmm — code sample of what you’re currently doing? Finding it hard to visualize…
d
Sure.
Copy code
# funcs.py
def func_1(func_1_params: dict) -> int:
    return 1

def func_2(func_1: int, func_2_params: dict) -> int:
    return 2

# run.py
import funcs
from hamilton import driver, base

if __name__ == "__main__":
    initial_config = {
        'func_1_params': {'a': 'b'},
        'func_2_params': {'c': 'd'},
    }
    adapter = base.SimplePythonGraphAdapter(base.DictResult())
    dr = driver.Driver(initial_config, hamilton_funcs, adapter=adapter)
    d = dr.execute(final_vars=['func_2'])
    print(d)
I have many funcs.
e
Thanks! Definitely doable (if I understand what you’re trying to do) — you can have them have the same param name, and use the
source
function. AFK now but I’ll get back to you. Also worth looking into
inject
d
Something like a config object, where it knows about every function and indexes the params for each func that way, perhaps?
e
Maybe, a little unclear though. To clarify — do you want every parameter to have the same name “param”, or have every function take in the same object?
d
your first interpretation
e
Ok, got it. So, you can do that with the
inject
decorator. Something like:
Copy code
@inject(param=source('param_1'))
def func_1(param: dict) -> ...:
    ...
Which would be functionally equivalent to naming the param
param_1
(Look in the docs though, this API is from memory cause I’m on my phone)
d
nice, easy fix.
e
That said, I’d argue that’s just kind of a level of indirection…
Reason you’d want to do this is if you want to reuse/test these functions in a bunch of different ways
d
What is the issue with indirection..? what type of soln is preferable in your view?
e
So it’s purely stylistic and there isn’t a “right” or “wrong” (well, the right way is the way you want it, as it’s your code :))
My opinion is that you want to make it concise and readable. So, if the function declares its input, then you immediately know what it’s doing/where it’s coming from (using the param name). If we use ‘inject’, you have to do two hops in reading it, and it’s an extra line of code
That said, we made ‘inject’ specifically for folks who want that indirection (and a few other odd cases), so I’m happy to be convinced
d
I see the issue. Thanks
👍 1
s
@David Wesolowski happy to jump on a call to chat / review your code if that helps give you better feedback. Just let us know 🙂
d
Thank you kindly. I'm still at the very early stages, let me build something more substantive. Cheers
👍 1