From fc2bbdeec62a9006fde4bbd004ad4e5c81601c7e Mon Sep 17 00:00:00 2001 From: Hans Ulrich Niedermann Date: Tue, 15 Jul 2008 23:51:00 +0200 Subject: More robust plugin duplicate detection When running pychecker, we got a few duplicate plugin errors due to multiple imports of the same module or something similar. --- src/nbblib/plugins.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/nbblib/plugins.py b/src/nbblib/plugins.py index c37b8a1..c3ab4fb 100644 --- a/src/nbblib/plugins.py +++ b/src/nbblib/plugins.py @@ -85,7 +85,12 @@ class NoPluginsRegistered(Exception): __all__.append('DuplicatePluginName') class DuplicatePluginName(Exception): """Raised when another plugin tries to register the same name""" - pass + def __init__(self, name, old, new): + super(DuplicatePluginName, self).__init__() + self.msg = "Duplicate plugin name %s, old plugin %s, new plugin %s" \ + % (repr(name), str(old), str(new)) + def __str__(self): + return self.msg __all__.append('PluginNoMatch') @@ -182,8 +187,12 @@ class PluginDict(dict): # This is the important difference between PluginDict and dict. def __setitem__(self, key, value): - if key in self: - raise DuplicatePluginName() + if (key in self): + old = self[key] + if old.__name__ == value.__name__ and old.__module__ == value.__module__: + pass + else: + raise DuplicatePluginName(name=key, old=self[key], new=value) else: super(PluginDict, self).__setitem__(key, value) -- cgit