Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions schemas/core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ classes:
extends: Object
isCoreType: true
mixins:
- ActivityMixin
properties:
actor:
type: WrapAS2[Object] | str | None
Expand Down
18 changes: 18 additions & 0 deletions src/apmodel/mixins/activity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from apmodel.activity import Accept, Reject
from apmodel.core import Activity
from apmodel.objects import Actor


class ActivityMixin:
def accept(self: "Activity", id: str, actor: "Actor") -> "Accept":
from apmodel.activity.accept import Accept

return Accept(id=id, actor=actor, object=self)

def reject(self: "Activity", id: str, actor: "Actor") -> "Reject":
from apmodel.activity.reject import Reject

return Reject(id=id, actor=actor, object=self)
Comment on lines +1 to +18
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current implementation of accept and reject requires an id as a positional argument. In many ActivityPub scenarios, the ID of a new activity might not be known at creation time (e.g., it's assigned by the server later) or should be optional.

Additionally, the actor parameter is typed strictly as Actor, but in practice, it is often provided as a URI string.

I suggest:

  1. Making id optional with a default of None.
  2. Swapping the order of actor and id to allow id to be optional while keeping actor required.
  3. Allowing actor to be a str.
  4. Adding from __future__ import annotations to simplify type hints and avoid circular evaluation issues at runtime.
Suggested change
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from apmodel.activity import Accept, Reject
from apmodel.core import Activity
from apmodel.objects import Actor
class ActivityMixin:
def accept(self: "Activity", id: str, actor: "Actor") -> "Accept":
from apmodel.activity.accept import Accept
return Accept(id=id, actor=actor, object=self)
def reject(self: "Activity", id: str, actor: "Actor") -> "Reject":
from apmodel.activity.reject import Reject
return Reject(id=id, actor=actor, object=self)
from __future__ import annotations
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from apmodel.activity import Accept, Reject
from apmodel.core import Activity
from apmodel.objects import Actor
class ActivityMixin:
def accept(self: Activity, actor: Actor | str, id: str | None = None) -> Accept:
from apmodel.activity.accept import Accept
return Accept(id=id, actor=actor, object=self)
def reject(self: Activity, actor: Actor | str, id: str | None = None) -> Reject:
from apmodel.activity.reject import Reject
return Reject(id=id, actor=actor, object=self)

2 changes: 1 addition & 1 deletion vendor/activitystreams
Loading