-
Notifications
You must be signed in to change notification settings - Fork 176
Description
Current behavior
If I define a step with the @dataloader decorator in a file that includes from __future__ import annotations, Hamilton cannot build the DAG because of type issues
Stack Traces
Traceback (most recent call last):
File "/Users/jlopezpena/Code/RA/pipelines/sample.py", line 3, in <module>
import functions
File "/Users/jlopezpena/Code/RA/pipelines/functions.py", line 6, in <module>
@dataloader()
~~~~~~~~~~^^
File "/Users/jlopezpena/Code/RA/pipelines/.venv/lib/python3.13/site-packages/hamilton/function_modifiers/base.py", line 60, in replace__call__
return call_fn(self, fn)
File "/Users/jlopezpena/Code/RA/pipelines/.venv/lib/python3.13/site-packages/hamilton/function_modifiers/base.py", line 102, in __call__
self.validate(fn)
~~~~~~~~~~~~~^^^^
File "/Users/jlopezpena/Code/RA/pipelines/.venv/lib/python3.13/site-packages/hamilton/function_modifiers/adapters.py", line 743, in validate
raise InvalidDecoratorException(f"Function: {fn.__qualname__} must return a tuple.")
hamilton.function_modifiers.base.InvalidDecoratorException: Function: sample_dataloader must return a tuple.
Screenshots
Steps to replicate behavior
Simple example:
# functions.py
from __future__ import annotations
from hamilton.function_modifiers import dataloader
@dataloader()
def sample_dataloader() -> tuple[list[str], dict]:
return ["a", "b", "c"], {}# main.py
from hamilton import driver
import functions
if __name__ == "__main__":
dr = driver.Builder().with_modules(functions)Then try running the main.py script with python main.py, which will result in the error above
Library & System Information
Python 3.12.7, hamilton 1.85.0, error replicated in Mac OS and Ubuntu Linux in a minimal virtual environment that just contains hamilton and its dependencies
Expected behavior
Hamilton should be able to build DAGs when types annotations are stringified
Additional context
This issue will eventually become a blocker for compatibility with python 3.14, where stringified annotations become the default (change already merged in python 3.14 alpha 0, though there is always the chance it could be reverted prior to release)
