Issue #14 resolved

PrioritizedHandler not sortable

Anonymous created an issue

Playing around with event handlers, you may encounter this error:

File "\irc\client.py", line 292 in add_global_handler

bisect.insort(event_handlers, handler)

TypeError: unorderable types: method() < method()

To fix it, replace this:

PrioritizedHandler = collections.namedtuple('PrioritizedHandler',
    ('priority', 'callback'))

with:

PrioritizedHandlerBase = collections.namedtuple('PrioritizedHandlerBase',
    ('priority', 'callback'))

class PrioritizedHandler(PrioritizedHandlerBase):
    def __lt__(self, other):
        return (self.priority < other.priority)

Comments (7)

  1. Jason R. Coombs repo owner

    I believe this issue only exists on Python 3. On Python 2, functions and methods are orderable, so the comparison allowed the callback to be used in the comparison.

  2. coffeeburrito

    Code for reproducing

    import irc.client
    
    class class1(object):
        def get_handler(self):
            return getattr(self, "_on_join")
    
        def _on_join(self, connection, event):
            pass
    
    class class2(object):
        def get_handler(self):
            return getattr(self, "_on_join")
    
        def _on_join(self, connection, event):
            pass
    
    c1 = class1()
    c2 = class2()
    client = irc.client.SimpleIRCClient()
    client.ircobj.add_global_handler("join", c1.get_handler())
    client.ircobj.add_global_handler("join", c2.get_handler())
    
  3. Log in to comment