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

feat: add description to signalinstance #339

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
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
21 changes: 21 additions & 0 deletions src/psygnal/_signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ def _create_signal_instance(
self.signature,
instance=instance,
name=name or self._name,
description=self.description,
check_nargs_on_connect=self._check_nargs_on_connect,
check_types_on_connect=self._check_types_on_connect,
reemission=self._reemission,
Expand Down Expand Up @@ -491,6 +492,19 @@ class Emitter:
reemission : Literal["immediate", "queued", "latest-only"] | None
See docstring for [`Signal`][psygnal.Signal] for details.
By default, `"immediate"`.
description : str
Optional descriptive text for the signal. (not used internally).

Attributes
----------
signature : Signature
Signature supported by this `SignalInstance`.
instance : Any
Object that emits this `SignalInstance`.
name : str
Name of this `SignalInstance`.
description : str
Description of this `SignalInstance`.

Raises
------
Expand All @@ -509,6 +523,7 @@ def __init__(
*,
instance: Any = None,
name: str | None = None,
description: str = "",
check_nargs_on_connect: bool = True,
check_types_on_connect: bool = False,
reemission: ReemissionVal = DEFAULT_REEMISSION,
Expand All @@ -521,6 +536,7 @@ def __init__(
"instance of `inspect.Signature`"
)

self._description = description
self._reemission = ReemissionMode.validate(reemission)
self._name = name
self._instance: Callable = self._instance_ref(instance)
Expand Down Expand Up @@ -572,6 +588,11 @@ def name(self) -> str:
"""Name of this `SignalInstance`."""
return self._name or ""

@property
def description(self) -> str:
"""Description of this `SignalInstance`."""
return self._description

def __repr__(self) -> str:
"""Return repr."""
name = f" {self._name!r}" if self._name else ""
Expand Down
10 changes: 10 additions & 0 deletions tests/test_psygnal.py
Original file line number Diff line number Diff line change
Expand Up @@ -1195,3 +1195,13 @@ def test_emit_loop_error_message_construction(strategy: ReemissionVal) -> None:
if strategy == "queued":
# check that we show a useful message for confusign queued signals
assert "NOTE" in str(e.value)


def test_description():
description = "A signal"

class T:
sig = Signal(description=description)

assert T.sig.description == description
assert T().sig.description == description
Loading