Skip to content

Commit

Permalink
add test; fix c optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
tschorr authored and mauritsvanrees committed May 4, 2017
1 parent 94c1879 commit 4afd29f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
10 changes: 7 additions & 3 deletions src/zope/interface/_zope_interface_coptimizations.c
Expand Up @@ -906,12 +906,16 @@ _lookup(lookup *self,
return NULL;
}

if (result == Py_None && default_ != NULL)
if (result == Py_None)
{
/* do not cache misses because the name is not included in the cache key */
if (default_ != NULL)
{
Py_INCREF(default_);
return default_;
}
Py_DECREF(Py_None);
Py_INCREF(default_);
return default_;
return result;
}
status = PyDict_SetItem(cache, key, result);
Py_DECREF(required);
Expand Down
20 changes: 16 additions & 4 deletions src/zope/interface/tests/test_adapter.py
Expand Up @@ -94,17 +94,17 @@ def test_multi_adapter_lookupAll_get_best_matches():
def test_multi_adapter_w_default():
"""
>>> registry = AdapterRegistry()
>>> registry.register([None, None], IB1, 'bob', 'A0')
>>> registry.lookup((IF1, IR1), IB0, 'bob')
'A0'
>>> registry.register([None, IR0], IB1, 'bob', 'A1')
>>> registry.lookup((IF1, IR1), IB0, 'bob')
'A1'
>>> registry.lookup((IF1, IR1), IB0, 'bruce')
>>> registry.register([None, IR1], IB1, 'bob', 'A2')
Expand Down Expand Up @@ -192,7 +192,7 @@ def test_adapter_hook_with_factory_producing_None():
"""
>>> registry = AdapterRegistry()
>>> default = object()
>>> class Object1(object):
... zope.interface.implements(IF0)
>>> class Object2(object):
Expand Down Expand Up @@ -293,6 +293,18 @@ def test_changing_declarations():
42
"""

def test_lookup_failure():
"""
>>> registry = AdapterRegistry()
>>> registry.register((), IF0, '', 42)
>>> def subsequent_lookup():
... print registry.lookup((), IF0, None)
... print registry.lookup((), IF0)
>>> subsequent_lookup()
None
42
"""

def test_correct_multi_adapter_lookup():
"""
>>> registry = AdapterRegistry()
Expand Down

0 comments on commit 4afd29f

Please sign in to comment.