Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix value receiver hinting #569

Merged
merged 3 commits into from
Jan 23, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions pyiron_workflow/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,9 @@ class DataChannel(FlavorChannel["DataChannel"], typing.Generic[ReceiverType], AB
more specific than the input channel.

In addition to connections, these channels can have a single partner
(:attr:`value_receiver: DataChannel`) that is of the _same_ class and obeys type
hints as though it were the "downstream" (input) partner in a connection.
(:attr:`value_receiver`) that is of the same data flavor and the same direction
(i.e. input or output) and obeys type hints as though it were the "downstream"
(input) partner in a connection.
Channels with such partners pass any data updates they receive directly to this
partner (via the :attr:`value` setter).
(This is helpful for passing data between scopes, where we want input at one scope
Expand Down Expand Up @@ -351,9 +352,9 @@ class DataChannel(FlavorChannel["DataChannel"], typing.Generic[ReceiverType], AB
when this channel is a value receiver. This can potentially be expensive, so
consider deactivating strict hints everywhere for production runs. (Default
is True, raise exceptions when type hints get violated.)
value_receiver (pyiron_workflow.compatibility.Self|None): Another channel of
the same class whose value will always get updated when this channel's
value gets updated.
value_receiver (ReceiverType|None): Another channel of the receiver type (i.e.
also a data flavor and matching input/output type) whose value will always
get updated when this channel's value gets updated.
"""

def __init__(
Expand All @@ -372,7 +373,7 @@ def __init__(
self.strict_hints = strict_hints
self.default = default
self.value = default # Implicitly type check your default by assignment
self.value_receiver: ReceiverType = value_receiver
self.value_receiver = value_receiver

@property
def value(self):
Expand All @@ -399,7 +400,7 @@ def _type_check_new_value(self, new_value):
)

@property
def value_receiver(self) -> Self | None:
def value_receiver(self) -> ReceiverType | None:
"""
Another data channel of the same type to whom new values are always pushed
(without type checking of any sort, not even when forming the couple!)
Expand All @@ -410,7 +411,7 @@ def value_receiver(self) -> Self | None:
return self._value_receiver

@value_receiver.setter
def value_receiver(self, new_partner: Self | None):
def value_receiver(self, new_partner: ReceiverType | None):
if new_partner is not None:
if not isinstance(new_partner, self.__class__):
raise TypeError(
Expand Down
Loading