I found this issue when debugging the failed CI for #632. A simple way to reproduce this issue is to retrieve the signature for completion function from the llm handler:
from effectful.handlers.llm.completions import completion
completion.__signature__
and it would complain about 'ClientSession' not being defined.
After a quick git bisect, I found that the issue was introduced by the commit fa2e420, which makes signature a lazy property. The ClientSession forward reference comes from litellm.completion. ClientSession refers to a class from aiohttp and the forward reference is there to delay the import of aiohttp. Here's a smaller, self-contained example demonstrating what's going on.
#a.py
from typing import TYPE_CHECKING
import b
from effectful.ops.syntax import defop
if TYPE_CHECKING:
from b import A
@defop
def foo(a : 'A') -> int:
return b.bar(a)
print(foo.__signature__)
#b.py
class A:
pass
def bar(a : A):
return 0
Here, mypy is happy with both files but __signature__ fails to resolve 'A' because the TYPE_CHECKING block can't be entered when effectful is running.The minimal example could have been made more realistic by adding another file in between so a.py doesn't have to import a potentially heavy library b at all until foo is called.
I'm not sure what the intended behavior should be here or how severe this issue is. In #632, implementing the completion operation triggers the error in the CI because that causes sphinx to inspect the signature of completion.
I found this issue when debugging the failed CI for #632. A simple way to reproduce this issue is to retrieve the signature for
completionfunction from the llm handler:and it would complain about 'ClientSession' not being defined.
After a quick
git bisect, I found that the issue was introduced by the commit fa2e420, which makes signature a lazy property. TheClientSessionforward reference comes fromlitellm.completion.ClientSessionrefers to a class fromaiohttpand the forward reference is there to delay the import ofaiohttp. Here's a smaller, self-contained example demonstrating what's going on.Here,
mypyis happy with both files but__signature__fails to resolve 'A' because theTYPE_CHECKINGblock can't be entered when effectful is running.The minimal example could have been made more realistic by adding another file in between soa.pydoesn't have to import a potentially heavy librarybat all untilfoois called.I'm not sure what the intended behavior should be here or how severe this issue is. In #632, implementing the
completionoperation triggers the error in the CI because that causessphinxto inspect the signature ofcompletion.