reducer path to strengthen too

This commit is contained in:
lda
2026-05-21 04:19:50 +07:00 Verified
parent 444b5735c1
commit d089e28c15
9 changed files with 201 additions and 38 deletions
+9 -3
View File
@@ -46,6 +46,12 @@ class SourceRef:
return value
if isinstance(value, str):
return cls.parse(value)
if isinstance(value, Mapping):
parts = value.get("parts")
if isinstance(parts, list | tuple) and all(
isinstance(part, str) for part in parts
):
return cls(tuple(parts))
raise TypeError("source ref must be a string")
@@ -101,9 +107,9 @@ class CapabilityRef:
return cls.parse(value)
if isinstance(value, dict):
source = value.get("source")
name = value.get("capability_key")
if isinstance(source, str) and isinstance(name, str):
return cls(source=SourceRef.parse(source), name=name)
name = value.get("capability_key", value.get("name"))
if isinstance(name, str):
return cls(source=SourceRef._validate(source), name=name)
raise TypeError(
"capability ref must be a string or {'source': str, 'capability_key': str}"
)