aboutsummaryrefslogtreecommitdiff
path: root/jb/models/assignment.py
diff options
context:
space:
mode:
Diffstat (limited to 'jb/models/assignment.py')
-rw-r--r--jb/models/assignment.py23
1 files changed, 12 insertions, 11 deletions
diff --git a/jb/models/assignment.py b/jb/models/assignment.py
index 39ae47c..5dd0167 100644
--- a/jb/models/assignment.py
+++ b/jb/models/assignment.py
@@ -1,6 +1,6 @@
import logging
from datetime import datetime, timezone
-from typing import Optional, TypedDict
+from typing import Optional, TypedDict, Any
from xml.etree import ElementTree
from mypy_boto3_mturk.type_defs import AssignmentTypeDef
@@ -10,7 +10,6 @@ from pydantic import (
ConfigDict,
model_validator,
PositiveInt,
- computed_field,
TypeAdapter,
ValidationError,
)
@@ -116,10 +115,12 @@ class Assignment(AssignmentStub):
default=None,
min_length=3,
max_length=2_000,
- help_text="The feedback string included with the call to the "
- "ApproveAssignment operation or the RejectAssignment "
- "operation, if the Requester approved or rejected the "
- "assignment and specified feedback.",
+ json_schema_extra={
+ "help_text": "The feedback string included with the call to the "
+ "ApproveAssignment operation or the RejectAssignment "
+ "operation, if the Requester approved or rejected the "
+ "assignment and specified feedback."
+ },
)
answer_xml: Optional[str] = Field(default=None, exclude=True)
@@ -131,7 +132,7 @@ class Assignment(AssignmentStub):
# --- Validators ---
@model_validator(mode="before")
- def set_tsid(cls, values: dict):
+ def set_tsid(cls, values: dict[str, Any]) -> dict[str, Any]:
if values.get("tsid") is None and (answer_xml := values.get("answer_xml")):
answer_dict = cls.parse_answer_xml(answer_xml)
tsid = answer_dict.get("tsid")
@@ -175,10 +176,10 @@ class Assignment(AssignmentStub):
if self.answer_xml is None:
return None
- return self.parse_answer_xml(self.answer_xml)
+ return self.parse_answer_xml(self.answer_xml) # type: ignore
@staticmethod
- def parse_answer_xml(answer_xml: str):
+ def parse_answer_xml(answer_xml: str) -> dict[str, Any]:
root = ElementTree.fromstring(answer_xml)
ns = {
"mt": "http://mechanicalturk.amazonaws.com/AWSMechanicalTurkDataSchemas/2005-10-01/QuestionFormAnswers.xsd"
@@ -186,8 +187,8 @@ class Assignment(AssignmentStub):
res = {}
for a in root.findall("mt:Answer", ns):
- name = a.find("mt:QuestionIdentifier", ns).text
- value = a.find("mt:FreeText", ns).text
+ name = a.find("mt:QuestionIdentifier", ns).text # type: ignore
+ value = a.find("mt:FreeText", ns).text # type: ignore
res[name] = value or ""
EXPECTED_KEYS = {"amt_assignment_id", "amt_worker_id", "tsid"}