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

@weave.op decorator destroys type information #3423

Open
pokey opened this issue Jan 16, 2025 · 2 comments
Open

@weave.op decorator destroys type information #3423

pokey opened this issue Jan 16, 2025 · 2 comments

Comments

@pokey
Copy link

pokey commented Jan 16, 2025

If I have the following code:

@weave.op()
def get_first_draft(
    previous_episodes: list[EpisodeCore],
    repository_data: dict,
) -> str:

VSCode type checking stops checking for valid args when I call the function, and autocomplete breaks for the args. The function is just interpreted as an Op object. See eg the hover

Image

This is a showstopper, as I rely heavily on autocomplete and type checking. Notice how I forgot to add an arg

@pokey
Copy link
Author

pokey commented Jan 16, 2025

For now, this is my workaround:

from collections.abc import Callable
from typing import TypeVar, cast

import weave

C = TypeVar("C", bound=Callable)


def weave_op():
    def ret(fn: C) -> C:
        return cast(C, weave.op()(fn))

    return ret

Which I then use like:

@weave_op()
def my_func(foo: str) -> str:
    ...

I don't support any of the @weave.op() arguments, and I don't expose any typing information about what I can use on an Op, but it's good enough for me for now. I think the correct thing would be to make the Op class have a generic type argument

@jamie-rasmussen
Copy link
Collaborator

Nice workaround! Glad you are unblocked. Will open an internal ticket to track this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants