Skip to content

Allow decorator use for functions defined in other modules #1281

@skrawcz

Description

@skrawcz

Is your feature request related to a problem? Please describe.
The following code throws errors:

Under: my_module/
__init__.py

from .base import a, z
from .base_extended import b_p, d, e

base.py

def a(input: int) -> int:
    return input * 2

def z(input: int) -> int:
    return input * 3

base_extended.py

from hamilton.function_modifiers import parameterize, value

from my_module import base

b_p = parameterize(
    b={"input":value(1)},
    c={"input":value(2)} 
)(base.a) 

def d(b: int, c: int) -> int:
    return b + c

Then in my run.py outside my_module.

from hamilton import driver
import my_module
dr = driver.Builder().with_modules(my_module).build()
dr.display_all_functions("base_extended.png")
print(dr.execute(['b', 'c']))

Throws two possible things (if you allow module overrides one error goes away):

  1. b is redefined twice.
  2. a is missing from the graph.

Describe the likely problem

  1. I think we're modifying the underlying function in the parameterize decorator which results in a being lost.
  2. Because of (2) we have a effectively as a function twice. Once via the parameterize decorator, once via module import. This then means that we're defining b and c twice.

Describe the solution you'd like

  1. we should be able to import functions and use them in a decorator - without impacting the use of that function in hamilton as a standalone by itself thing.
  2. with (1) resolved I think things should then just work.

Describe alternatives you've considered
N/A

Additional context
Comes from a problem a user ran into in slack.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions