fediverse-devnet / fediverse-devnet/feditest

activitypub.Collection: contains_item_with_id type mismatch

Open
#291 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
37
Forks
6
PR merge metrics
No merged PRs in 30d

Description

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()`.

```python
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
# ...
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.