# HG changeset patch # User Sylvain Thénault # Date 1280138812 -7200 # Node ID e1c43115af3bd90321a16ee2689d78946d9d420b # Parent 764d232f201c540c19fd066691a6636881bfb54d [selector] adjuts score returned by the adaptable selector to get correct priority over is_instance diff -r 764d232f201c -r e1c43115af3b selectors.py --- a/selectors.py Mon Jul 26 12:06:49 2010 +0200 +++ b/selectors.py Mon Jul 26 12:06:52 2010 +0200 @@ -462,15 +462,21 @@ (usually entities) should be adaptable. One of them should be selectable when multiple identifiers are given. """ - # being adaptable to an interface takes precedence other is_instance('Any'), - # hence return 2 (is_instance('Any') score is 1) - selectable_score = 2 def __init__(self, *regids): super(adaptable, self).__init__('adapters', *regids) def __call__(self, cls, req, **kwargs): kwargs.setdefault('accept_none', False) - return super(adaptable, self).__call__(cls, req, **kwargs) + # being adaptable to an interface should takes precedence other is_instance('Any'), + # but not other explicit is_instance('SomeEntityType'), and: + # * is_instance('Any') score is 1 + # * is_instance('SomeEntityType') score is at least 2 + score = super(adaptable, self).__call__(cls, req, **kwargs) + if score >= 2: + return score - 0.5 + if score == 1: + return score + 0.5 + return score # rset selectors ##############################################################