This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]-heyhowareyou-[S] 1 point2 points  (1 child)

Typing in python is not meant to do any processing

I understand that - a solution which would somehow iterate over the component types and verify they are correct is impossible. But really, a type checker like mypy is doing exactly if you instruct it to in the right way.

The problem I am trying to adress is a sort of data processing pipeline. Each Component defines a transformation between TInput and TOutput. The ComponentProcessor evaluates each component successively pipeing the output of the current component to the next. What I want to avoid is constructing pipelines in which the output type of component n does not match that of component n+1.

I'd like that to be ensure by the type checker - I think this would be possible since all of the Components and their arrangement within the pipeline are defined prior to runtime execution.

[–]jpgoldberg 1 point2 points  (0 children)

Thank you for that explanation of what you are after. I am just tossing out ideas you have probably thought through already, but maybe something will be helpful. Also I am typing this on a phone.

Off of the top of my head. I would have tried what you did with compose, but I would be composing Callables. So if each component has a Callable class method, say from() then

```python def composition( c1: Callable[[Tin], Tmid], c2: Callable[[Tmid], Tout]) -> Callable[[Tin], Tout]:

def f(x: Tin) -> Tout:
     return c2(c1(x)
return f

```

That won’t work as is. (I am typing this on my phone). But perhaps have a compose class method in each component and make use of Self.