Skip to content

Commit

Permalink
Added signal names and repr.
Browse files Browse the repository at this point in the history
repr is <signalslot.Signal: signal_name>.

For unamed signals, it is <signalslot.Signal: NO_NAME>. The ugly caps
are to make sure you notice you are calling repr on a signal with no
name, which you shouldn't.

Fixes #2
  • Loading branch information
madjar committed Aug 5, 2014
1 parent 6064c55 commit f25cae2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion signalslot/signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ class Signal(object):
>>> conf_pre_load.is_connected(yourmodule_conf)
False
"""
def __init__(self, args=None):
def __init__(self, args=None, name=None):
self.slots = []
self.args = args or []
self.name = name

def connect(self, slot):
"""
Expand Down Expand Up @@ -117,3 +118,6 @@ def __eq__(self, other):
True
"""
return self.slots == other.slots

def __repr__(self):
return '<signalslot.Signal: %s>' % (self.name or 'NO_NAME')
9 changes: 9 additions & 0 deletions signalslot/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ def test_disconnect_does_not_fail_on_not_connected_slot(self, inspect):
self.signal_a.disconnect(self.slot_b)


def test_anonymous_signal_has_nice_repr():
signal = Signal()
assert repr(signal) == '<signalslot.Signal: NO_NAME>'

def test_named_signal_has_a_nice_repr():
signal = Signal(name='update_stuff')
assert repr(signal) == '<signalslot.Signal: update_stuff>'


class TestSignalConnect(object):
def setup_method(self, method):
self.signal = Signal()
Expand Down

0 comments on commit f25cae2

Please sign in to comment.