The contains_item_with_id predicate requires id to be a str, but Collection.contains is iterating over instances of AnyObject returned by self.items().
def contains(self, matcher: Callable[[AnyObject],bool]) -> bool:
"""
Returns true if this Collection contains an item, as determined by the
matcher object. This method passes the members of this collection to the
matcher one at a time, and the matcher decides when there is a match.
"""
for item in self.items(): # <-- iterates AnyObject, not str
if matcher(item):
return True
return False
def contains_item_with_id(self, id: str) -> bool:
"""
Convenience method that looks for items that are simple object identifiers.
FIXME: this can be much more complicated in ActivityStreams, but this
implementation is all we need right now.
"""
return self.contains(lambda candidate: id == candidate if isinstance(candidate,str) else False) # <-- requires str
# ...
def items(self) -> Iterator[AnyObject]:
items = self._delegate.json_field('orderedItems' if self.is_ordered() else 'items')
if items is not None:
for item in items:
if isinstance(item,str):
yield AnyObject(item) # <-- not yielding a str
# ...
The contains_item_with_id predicate requires
id
to be astr
, butCollection.contains
is iterating over instances ofAnyObject
returned byself.items()
.