Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

activitypub.Collection: contains_item_with_id type mismatch #291

Open
steve-bate opened this issue Aug 1, 2024 · 1 comment
Open

activitypub.Collection: contains_item_with_id type mismatch #291

steve-bate opened this issue Aug 1, 2024 · 1 comment

Comments

@steve-bate
Copy link
Member

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
# ...
@jernst
Copy link
Member

jernst commented Oct 18, 2024

Code currently commented out, but leaving this here.

@jernst jernst removed this from the FediTest 0.6 released milestone Oct 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants