# HG changeset patch # User Sylvain Thenault # Date 1228496857 -3600 # Node ID 73aa037344258d025757ce08f0bc279e6d70de4c # Parent 312024cbe717e52f7e1e62fce253b14d88b92093 check we don't get selection ambiguity: if yes, log error in production env, raise in other modes diff -r 312024cbe717 -r 73aa03734425 vregistry.py --- a/vregistry.py Fri Dec 05 18:06:58 2008 +0100 +++ b/vregistry.py Fri Dec 05 18:07:37 2008 +0100 @@ -334,14 +334,24 @@ raise NoSelectableObject if not object apply """ - score, winner = 0, None + score, winners = 0, [] for vobject in vobjects: vobjectscore = vobject.__select__(*args, **kwargs) if vobjectscore > score: - score, winner = vobjectscore, vobject - if winner is None: + score, winners = vobjectscore, [vobject] + elif vobjectscore > 0 and vobjectscore == score: + winners.append(vobject) + if not winners: raise NoSelectableObject('args: %s\nkwargs: %s %s' % (args, kwargs.keys(), [repr(v) for v in vobjects])) + if len(winners) > 1: + if self.config.mode == 'installed': + self.error('select ambiguity, args: %s\nkwargs: %s %s', + args, kwargs.keys(), [repr(v) for v in winners]) + else: + raise Exception('select ambiguity, args: %s\nkwargs: %s %s' + % (args, kwargs.keys(), [repr(v) for v in winners])) + winner = winners[0] # return the result of the .selected method of the vobject return winner.selected(*args, **kwargs)