apache / apache/hamilton

Allow decorator use for functions defined in other modules

Open
#1,281 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
Jupyter Notebook
Stars
2.6k
Forks
213
PR merge metrics
No merged PRs in 30d

Description

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

Under: my_module/
`__init__.py`
```python
from .base import a, z
from .base_extended import b_p, d, e
```

`base.py`
```python
def a(input: int) -> int:
return input * 2

def z(input: int) -> int:
return input * 3
```
`base_extended.py`
```python
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.
```python
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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.