:wave: I have a couple tasks and a workflow that ...
# ask-the-community
👋 I have a couple tasks and a workflow that calls those. The issue I’m facing is that since
returns a union of
the typechecker’s utility is greatly reduced. Is there a paved path to preserving the original function’s return type? Or some other way that is peaceful with the typechecker (using pyright)?
Copy code
class InnerDC:
    subfield: str
    subpath: str

class OuterDC:
    name: str
    path: str
    inner_dc: InnerDC
    uid: Optional[int] = None

def make_test_dc(name: str, path: str, subfield: str, subpath: str) -> OuterDC:
    return OuterDC(name=name, path=path, inner_dc=InnerDC(subfield=subfield, subpath=subpath))

def extract_subpath(dc: OuterDC) -> str:
    return dc.inner_dc.subpath

def wf(name: str, path: str, subfield: str, subpath: str) -> str:
    dc = make_test_dc(name=name, path=path, subfield=subfield, subpath=subpath)
    return extract_subpath(dc=dc)
currently no. apologies.
this is a known issue though, and something we were at least planning on working on… soon
I see, thanks for the info. Just out of curiosity, what would the solution look like? Currently I am using a
protocol to overload the return type to be the same as the decorated function which is a decent compromise for now, but with some obvious downsides (no kwargs info, no docstrings etc)
the solution has yet to be discovered tbh. we were gonna start thinking about it next week tbh. at least planning to.
but it’d likely involve exporting a series of pyi files along with flytekit that can hopefully teach lsps how to interpret flytekit code correctly.
That sounds amazing! Much appreciated 🙏
+1 to this
still working on this.
all the issues we’ve collected. feel free to upvote one or all of them. this is something we definitely need to work on
cc @Eduardo Apolinario (eapolinario) @Thomas Fan
Definitely more of a nice-to-have, but it is a bit ironic how typing is at the core of flyte, but we don’t get good typing support with mypy, etc at the workflow and task definitions.
yeah i also feel that way
we’ll work on it.
rest assured you're not the only one, @Len Strnad . We're actively looking for solutions. 🙂
I opened https://github.com/flyteorg/flytekit/pull/2411 to get the ball rolling. I do not think it is the most correct solution, but it does enable type checking.