src/pyams_utils/adapter.py
changeset 185 b713404fd6e5
parent 183 5e239a213d1d
child 186 c08b45bbed38
--- 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: