Skip to content

[Bug]: weave.op decorator does not maintain type hints #5876

@ShravanSunder

Description

@ShravanSunder

Describe the bug

In the example below blah is typed as any in pyright etc. Which destroys any type safety we have in a repo.

import weave


class ATestObj(weave.Object):
    a: int

    @weave.op
    def a_test_add(self, b: int) -> int:
        return self.a + b


d = ATestObj(a=1)
blah = d.a_test_add(b=2)

Why is this the case? And why not use a simple t.cast in the decorator or helper to allow proper types?

def op(...) -> Callable[[Callable[P, R]], Callable[P, R]]:  
    def wrapper(func: Callable[P, R]) -> Callable[P, R]:  
        # ... existing logic ...  
        return cast(Callable[P, R], op_wrapper)  # force casting

Weave Project Link

No response

Screenshots

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions