merge default doc-dc
authorDamien Correia
Fri, 25 May 2018 17:06:43 +0200
branchdoc-dc
changeset 259 931959214ed9
parent 258 86d0f27c7f46 (current diff)
parent 185 b713404fd6e5 (diff)
child 260 1ed791a40890
merge default
--- a/src/pyams_utils/adapter.py	Fri May 25 15:21:23 2018 +0200
+++ b/src/pyams_utils/adapter.py	Fri May 25 17:06:43 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: