# HG changeset patch # User Thierry Florac # Date 1527253937 -7200 # Node ID b713404fd6e5dc79731b2c64463c799c3baa8916 # Parent d4a0668c7ee0ccc4ac22c2a1ce403adff771deb8 Allow empty factory when looking for annotations adapter diff -r d4a0668c7ee0 -r b713404fd6e5 src/pyams_utils/adapter.py --- a/src/pyams_utils/adapter.py Fri May 25 14:27:56 2018 +0200 +++ b/src/pyams_utils/adapter.py Fri May 25 15:12:17 2018 +0200 @@ -131,14 +131,14 @@ return wrapped -def get_annotation_adapter(context, key, factory, markers=None, notify=True, +def get_annotation_adapter(context, key, factory=None, markers=None, notify=True, locate=True, parent=None, name=None): """Get an adapter via object's annotations, creating it if not existent :param object context: context object which should be adapted :param str key: annotations key to look for :param factory: if annotations key is not found, this is the factory which will be used to - create a new object + create a new object; if factory is None and is requested object can't be found, None is returned :param markers: if not None, list of marker interfaces which created adapter should provide :param bool=True notify: if 'False', no notification event will be sent on object creation :param bool=True locate: if 'False', the new object is not attached to any parent @@ -151,6 +151,8 @@ return None adapter = annotations.get(key) if adapter is None: + if factory is None: + return None adapter = annotations[key] = factory() if markers: for marker in markers: