Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

from __future__ import annotations breaks decorators #1259

Closed
jlopezpena opened this issue Dec 17, 2024 · 2 comments
Closed

from __future__ import annotations breaks decorators #1259

jlopezpena opened this issue Dec 17, 2024 · 2 comments
Labels
triage label for issues that need to be triaged.

Comments

@jlopezpena
Copy link

jlopezpena commented Dec 17, 2024

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

image

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)

@jlopezpena jlopezpena added the triage label for issues that need to be triaged. label Dec 17, 2024
@elijahbenizzy
Copy link
Collaborator

Hey! Should be straightforward but need to scope. Taking a look at this + #1260 as well.

elijahbenizzy added a commit that referenced this issue Dec 17, 2024
This makes it work with __future__.annotations. See #1259.
elijahbenizzy added a commit that referenced this issue Dec 17, 2024
This makes it work with __future__.annotations. See #1259.
@elijahbenizzy
Copy link
Collaborator

Hey! Fix is released in 1.85.1. Closing -- open up if you need anything else!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage label for issues that need to be triaged.
Projects
None yet
Development

No branches or pull requests

2 participants