Skip to content

Commit

Permalink
Make a generic version of HasChannel
Browse files Browse the repository at this point in the history
Signed-off-by: liamhuber <[email protected]>
  • Loading branch information
liamhuber committed Jan 16, 2025
1 parent 6af74e0 commit d98b77e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
16 changes: 12 additions & 4 deletions pyiron_workflow/mixin/has_interface_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from __future__ import annotations

from abc import ABC, abstractmethod
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Generic, TypeVar

if TYPE_CHECKING:
from pyiron_workflow.channels import Channel
Expand Down Expand Up @@ -69,9 +69,7 @@ def full_label(self) -> str:

class HasChannel(ABC):
"""
A mix-in class for use with the :class:`Channel` class.
A :class:`Channel` is able to (attempt to) connect to any child instance of :class:`HasConnection`
by looking at its :attr:`connection` attribute.
A mix-in class for use with the :class:`Channel` class and its children.
This is useful for letting channels attempt to connect to non-channel objects
directly by pointing them to some channel that object holds.
Expand All @@ -83,6 +81,16 @@ def channel(self) -> Channel:
pass


ChannelType = TypeVar("ChannelType", bound="Channel")


class HasGenericChannel(HasChannel, Generic[ChannelType], ABC):
@property
@abstractmethod
def channel(self) -> ChannelType:
pass


class HasRun(ABC):
"""
A mixin to guarantee that the :meth:`run` method exists.
Expand Down
4 changes: 2 additions & 2 deletions pyiron_workflow/mixin/single_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from abc import ABC, abstractmethod

from pyiron_workflow.mixin.has_interface_mixins import HasChannel, HasLabel
from pyiron_workflow.mixin.has_interface_mixins import HasGenericChannel, HasLabel
from pyiron_workflow.mixin.injection import (
OutputDataWithInjection,
OutputsWithInjection,
Expand All @@ -18,7 +18,7 @@ class AmbiguousOutputError(ValueError):
"""Raised when searching for exactly one output, but multiple are found."""


class ExploitsSingleOutput(HasLabel, HasChannel, ABC):
class ExploitsSingleOutput(HasLabel, HasGenericChannel[OutputDataWithInjection], ABC):
@property
@abstractmethod
def outputs(self) -> OutputsWithInjection:
Expand Down

0 comments on commit d98b77e

Please sign in to comment.