feat(nodes): attempt to look up invoke return types by name

This commit is contained in:
psychedelicious 2024-04-29 09:12:33 +10:00
parent f526f0ae5f
commit 2cda6cbf14

View File

@ -4,6 +4,7 @@ from __future__ import annotations
import inspect import inspect
import re import re
import sys
import warnings import warnings
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from enum import Enum from enum import Enum
@ -481,7 +482,11 @@ def invocation(
# And validate that `invoke()` returns a subclass of `BaseInvocationOutput # And validate that `invoke()` returns a subclass of `BaseInvocationOutput
invoke_return_annotation = signature(cls.invoke).return_annotation invoke_return_annotation = signature(cls.invoke).return_annotation
try: try:
if isinstance(invoke_return_annotation, str):
invoke_return_annotation = getattr(sys.modules[cls.__module__], invoke_return_annotation)
assert invoke_return_annotation is not BaseInvocationOutput assert invoke_return_annotation is not BaseInvocationOutput
# TODO(psyche): If `invoke()` is not defined, `return_annotation` ends up as the string # TODO(psyche): If `invoke()` is not defined, `return_annotation` ends up as the string
# "BaseInvocationOutput". This may be a pydantic bug: https://github.com/pydantic/pydantic/issues/7978 # "BaseInvocationOutput". This may be a pydantic bug: https://github.com/pydantic/pydantic/issues/7978