Skip to content

Commit a3b2999

Browse files
Merge pull request #2 from CdnCentreForChildProtection/fix-match_type_allow_none
Let `None` MatchType be parsed into `None`
2 parents 16642d2 + 6f2335d commit a3b2999

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

arachnid_shield_sdk/models/scanned_media.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ class MatchType(str, Enum):
2121
Exact = "exact"
2222
Near = "near"
2323

24+
@classmethod
25+
def from_value(cls, value: typing.Optional[str]) -> typing.Optional["MatchType"]:
26+
if value is None:
27+
return None
28+
return cls(value)
29+
30+
2431
@dataclasses.dataclass
2532
class NearMatchDetail:
2633
"""A record of a near match (based on perceptual hashing) to a known image in our database.
@@ -109,7 +116,7 @@ def from_dict(cls, src_dict: typing.Dict[str, typing.Any]) -> "ScannedMedia":
109116
sha1_base32=src_dict["sha1_base32"],
110117
size_bytes=src_dict["size_bytes"],
111118
classification=classification,
112-
match_type=src_dict["match_type"],
119+
match_type=MatchType.from_value(src_dict["match_type"]),
113120
near_match_details=near_match_details,
114121
)
115122

arachnid_shield_sdk/models/scanned_pdq.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def from_dict(cls, src_dict: typing.Dict[str, typing.Any]) -> "PDQMatch":
3232
classification = MediaClassification(classification)
3333
return cls(
3434
classification=classification,
35-
match_type=MatchType(src_dict["match_type"]),
35+
match_type=MatchType.from_value(src_dict["match_type"]),
3636
near_match_details=near_match_details,
3737
)
3838

@@ -62,7 +62,7 @@ def from_dict(cls, src_dict: typing.Dict[str, typing.Any]) -> "ScannedPDQHashes"
6262
near_match_details = NearMatchDetail.from_dict(near_match_details)
6363
scanned_hashes[key] = PDQMatch(
6464
classification=value['classification'],
65-
match_type=MatchType(value['match_type']),
65+
match_type=MatchType.from_value(value['match_type']),
6666
near_match_details=near_match_details
6767
)
6868
return cls(

0 commit comments

Comments
 (0)