Skip to content

Commit

Permalink
Merge pull request #1932 from takluyver/i1916
Browse files Browse the repository at this point in the history
Fix adding functions to CommandChainDispatcher with equal priority on Py 3
  • Loading branch information
takluyver committed Jun 12, 2012
2 parents e5d53ac + a8a4130 commit b6137d2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 3 additions & 2 deletions IPython/core/hooks.py
Expand Up @@ -41,7 +41,7 @@ def calljed(self,filename, linenum):
# the file COPYING, distributed as part of this software.
#*****************************************************************************

import os, bisect
import os
import subprocess
import sys

Expand Down Expand Up @@ -146,7 +146,8 @@ def __str__(self):

def add(self, func, priority=0):
""" Add a func to the cmd chain with given priority """
bisect.insort(self.chain,(priority,func))
self.chain.append((priority, func))
self.chain.sort(key=lambda x: x[0])

def __iter__(self):
""" Return all objects in chain.
Expand Down
6 changes: 6 additions & 0 deletions IPython/core/tests/test_hooks.py
Expand Up @@ -73,3 +73,9 @@ def test_command_chain_dispatcher_fofo():
nt.assert_true(okay1.called)
nt.assert_false(fail2.called)
nt.assert_false(okay2.called)

def test_command_chain_dispatcher_eq_priority():
okay1 = Okay(u'okay1')
okay2 = Okay(u'okay2')
dp = CommandChainDispatcher([(1, okay1)])
dp.add(okay2, 1)

0 comments on commit b6137d2

Please sign in to comment.