|
21 | 21 | from __future__ import annotations |
22 | 22 |
|
23 | 23 | from dataclasses import dataclass, field |
24 | | -from typing import TYPE_CHECKING, Any |
| 24 | +from typing import TYPE_CHECKING, Any, cast |
25 | 25 |
|
26 | 26 | if TYPE_CHECKING: |
27 | 27 | from agentscore_commerce.identity.types import AssessResult |
@@ -279,28 +279,29 @@ async def ucp_profile(): |
279 | 279 | # ``raw``; if a caller hand-constructs an AssessResult with mismatched |
280 | 280 | # typed and raw verification blocks, both languages must pick the same |
281 | 281 | # source so a profile signed in one verifies in the other. |
282 | | - typed_op = getattr(data, "operator_verification", None) |
283 | | - if typed_op is not None and not isinstance(typed_op, dict): |
| 282 | + typed_op = data.operator_verification |
| 283 | + operator_verification: dict[str, Any] = {} |
| 284 | + if isinstance(typed_op, dict): |
| 285 | + operator_verification = cast("dict[str, Any]", typed_op) |
| 286 | + elif typed_op is not None: |
284 | 287 | # Convert OperatorVerification dataclass to a plain dict. |
285 | 288 | operator_verification = { |
286 | 289 | "level": getattr(typed_op, "level", None), |
287 | 290 | "operator_type": getattr(typed_op, "operator_type", None), |
288 | 291 | "verified_at": getattr(typed_op, "verified_at", None), |
289 | 292 | } |
290 | | - else: |
291 | | - operator_verification = typed_op |
292 | 293 | if not operator_verification: |
293 | 294 | raw = data.raw or {} |
294 | | - operator_verification = raw.get("operator_verification") if isinstance(raw, dict) else None |
295 | | - if not isinstance(operator_verification, dict): |
296 | | - operator_verification = {} |
| 295 | + raw_op = raw.get("operator_verification") if isinstance(raw, dict) else None |
| 296 | + if isinstance(raw_op, dict): |
| 297 | + operator_verification = raw_op |
297 | 298 |
|
298 | | - account_verification = getattr(data, "account_verification", None) |
| 299 | + account_verification: dict[str, Any] = data.account_verification or {} |
299 | 300 | if not account_verification: |
300 | 301 | raw = data.raw or {} |
301 | | - account_verification = raw.get("account_verification") if isinstance(raw, dict) else None |
302 | | - if not isinstance(account_verification, dict): |
303 | | - account_verification = {} |
| 302 | + raw_av = raw.get("account_verification") if isinstance(raw, dict) else None |
| 303 | + if isinstance(raw_av, dict): |
| 304 | + account_verification = raw_av |
304 | 305 | # `dict.get(k) or DEFAULT` (not `dict.get(k, DEFAULT)`) coerces both a |
305 | 306 | # missing key AND a present-but-falsy (None / "") value to the default, |
306 | 307 | # matching the node sibling's `||` semantics. The API can return |
|
0 commit comments