@@ -120,6 +120,10 @@ def __hash__(self):
120120 return hash ((self .term , self .modifiers ))
121121
122122
123+ def _annotation_factory (a_str : str , * args ):
124+ return Annotation (a_str )
125+
126+
123127class AnnotationCollection (Set ):
124128 """Object that parses and processes localisation (or other) annotation
125129 strings of the form ".
@@ -130,8 +134,9 @@ def __init__(
130134 self ,
131135 annotations_string : str ,
132136 annotation_factory : Callable [[str ], Annotation ] = (
133- lambda a_str : Annotation ( a_str )
137+ _annotation_factory
134138 ),
139+ annotation_factory_extra_args : tuple = (),
135140 ):
136141 """Creates a new `AnnotationCollection` from the given annotation
137142 string.
@@ -147,13 +152,14 @@ def __init__(
147152 """
148153 if annotations_string != "" :
149154 self ._annotations = frozenset ([
150- annotation_factory (a_str )
155+ annotation_factory (a_str , * annotation_factory_extra_args )
151156 for a_str in ANNOT_SPLIT_RE .split (annotations_string )
152157 ])
153158 else :
154159 self ._annotations = frozenset ([])
155160
156161 self ._annotation_factory = annotation_factory
162+ self ._annotation_factory_extra_args = annotation_factory_extra_args
157163
158164 def __contains__ (self , item : str | Annotation ):
159165 """Returns whether the annotation collection contains the given
@@ -165,7 +171,8 @@ def __contains__(self, item: str | Annotation):
165171 converted to an `Annotation` object.
166172 """
167173 if isinstance (item , str ):
168- annot = self ._annotation_factory (item )
174+ annot = self ._annotation_factory (
175+ item , * self ._annotation_factory_extra_args )
169176 else :
170177 annot = item
171178 term_re = re .compile (annot .term )
0 commit comments