@@ -49,13 +49,13 @@ def serial_from_msg_or_serial(msg_or_serial):
4949 return message_serial
5050
5151
52- def construct_validate_annotation (msg_or_serial , annotation : dict ) :
52+ def construct_validate_annotation (msg_or_serial , annotation : Annotation ) -> Annotation :
5353 """
5454 Construct and validate an Annotation from input values.
5555
5656 Args:
5757 msg_or_serial: Either a string serial or a Message object
58- annotation: Dict of annotation properties or Annotation object
58+ annotation: Annotation object
5959
6060 Returns:
6161 Annotation: The constructed annotation
@@ -65,18 +65,17 @@ def construct_validate_annotation(msg_or_serial, annotation: dict):
6565 """
6666 message_serial = serial_from_msg_or_serial (msg_or_serial )
6767
68- if not annotation or ( not isinstance (annotation , dict ) and not isinstance ( annotation , Annotation ) ):
68+ if not annotation or not isinstance (annotation , Annotation ):
6969 raise AblyException (
7070 message = 'Second argument of annotations.publish() must be a dict or Annotation '
7171 '(the intended annotation to publish)' ,
7272 status_code = 400 ,
7373 code = 40003 ,
7474 )
7575
76- annotation_values = annotation .copy ()
77- annotation_values ['message_serial' ] = message_serial
78-
79- return Annotation .from_values (annotation_values )
76+ return annotation ._copy_with (
77+ message_serial = message_serial ,
78+ )
8079
8180
8281class RestAnnotations :
@@ -109,15 +108,15 @@ def __base_path_for_serial(self, serial):
109108 async def publish (
110109 self ,
111110 msg_or_serial ,
112- annotation : dict | Annotation ,
111+ annotation : Annotation ,
113112 params : dict | None = None ,
114113 ):
115114 """
116115 Publish an annotation on a message.
117116
118117 Args:
119118 msg_or_serial: Either a message serial (string) or a Message object
120- annotation: Dict containing annotation properties (type, name, data, etc.) or Annotation object
119+ annotation: Annotation object
121120 params: Optional dict of query parameters
122121
123122 Returns:
@@ -152,7 +151,7 @@ async def publish(
152151 async def delete (
153152 self ,
154153 msg_or_serial ,
155- annotation : dict | Annotation ,
154+ annotation : Annotation ,
156155 params : dict | None = None ,
157156 ):
158157 """
@@ -163,7 +162,7 @@ async def delete(
163162
164163 Args:
165164 msg_or_serial: Either a message serial (string) or a Message object
166- annotation: Dict containing annotation properties or Annotation object
165+ annotation: Annotation object
167166 params: Optional dict of query parameters
168167
169168 Returns:
@@ -172,13 +171,11 @@ async def delete(
172171 Raises:
173172 AblyException: If the request fails or inputs are invalid
174173 """
175- # Set action to delete
176- if isinstance (annotation , Annotation ):
177- annotation_values = annotation .as_dict ()
178- else :
179- annotation_values = annotation .copy ()
180- annotation_values ['action' ] = AnnotationAction .ANNOTATION_DELETE
181- return await self .publish (msg_or_serial , annotation_values , params )
174+ return await self .publish (
175+ msg_or_serial ,
176+ annotation ._copy_with (action = AnnotationAction .ANNOTATION_DELETE ),
177+ params ,
178+ )
182179
183180 async def get (self , msg_or_serial , params : dict | None = None ):
184181 """
0 commit comments