Skip to content

Let None MatchType be parsed into None #2

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

Merged
merged 1 commit into from
Jul 17, 2025
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
9 changes: 8 additions & 1 deletion arachnid_shield_sdk/models/scanned_media.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ class MatchType(str, Enum):
Exact = "exact"
Near = "near"

@classmethod
def from_value(cls, value: typing.Optional[str]) -> typing.Optional["MatchType"]:
if value is None:
return None
return cls(value)


@dataclasses.dataclass
class NearMatchDetail:
"""A record of a near match (based on perceptual hashing) to a known image in our database.
Expand Down Expand Up @@ -109,7 +116,7 @@ def from_dict(cls, src_dict: typing.Dict[str, typing.Any]) -> "ScannedMedia":
sha1_base32=src_dict["sha1_base32"],
size_bytes=src_dict["size_bytes"],
classification=classification,
match_type=src_dict["match_type"],
match_type=MatchType.from_value(src_dict["match_type"]),
near_match_details=near_match_details,
)

Expand Down
4 changes: 2 additions & 2 deletions arachnid_shield_sdk/models/scanned_pdq.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def from_dict(cls, src_dict: typing.Dict[str, typing.Any]) -> "PDQMatch":
classification = MediaClassification(classification)
return cls(
classification=classification,
match_type=MatchType(src_dict["match_type"]),
match_type=MatchType.from_value(src_dict["match_type"]),
near_match_details=near_match_details,
)

Expand Down Expand Up @@ -62,7 +62,7 @@ def from_dict(cls, src_dict: typing.Dict[str, typing.Any]) -> "ScannedPDQHashes"
near_match_details = NearMatchDetail.from_dict(near_match_details)
scanned_hashes[key] = PDQMatch(
classification=value['classification'],
match_type=MatchType(value['match_type']),
match_type=MatchType.from_value(value['match_type']),
near_match_details=near_match_details
)
return cls(
Expand Down