diff --git a/IPython/core/hooks.py b/IPython/core/hooks.py index 742393f..7e01e05 100644 --- a/IPython/core/hooks.py +++ b/IPython/core/hooks.py @@ -41,7 +41,8 @@ somewhere in your configuration files or ipython command line. # the file COPYING, distributed as part of this software. #***************************************************************************** -import os, bisect +import os +import operator import subprocess import sys @@ -146,7 +147,8 @@ class CommandChainDispatcher: 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=operator.itemgetter(0)) def __iter__(self): """ Return all objects in chain. diff --git a/IPython/core/tests/test_hooks.py b/IPython/core/tests/test_hooks.py index ec32bf5..f44674c 100644 --- a/IPython/core/tests/test_hooks.py +++ b/IPython/core/tests/test_hooks.py @@ -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)