Consume formatter hints
This commit is contained in:
@@ -96,6 +96,37 @@ def formatter_hints(metadata: dict[str, Any]) -> dict[str, list[str]]:
|
||||
return {route: hints for route, hints in normalized.items() if hints}
|
||||
|
||||
|
||||
def formatter_hints_for_route(row_or_hints: Any, route: str) -> list[str]:
|
||||
route = normalize_formatter_route(route)
|
||||
if not route or not isinstance(row_or_hints, dict):
|
||||
return []
|
||||
|
||||
if isinstance(row_or_hints.get("formatter_hints"), dict):
|
||||
raw_hints = row_or_hints.get("formatter_hints") or {}
|
||||
elif "formatter_hint" in row_or_hints:
|
||||
raw_hints = formatter_hints(row_or_hints)
|
||||
else:
|
||||
raw_hints = row_or_hints
|
||||
|
||||
normalized: dict[str, list[str]] = {}
|
||||
if isinstance(raw_hints, dict):
|
||||
for raw_route, values in raw_hints.items():
|
||||
normalized_route = normalize_formatter_route(raw_route)
|
||||
if not normalized_route:
|
||||
continue
|
||||
for value in _list_from(values):
|
||||
hint = _clean_hint(value)
|
||||
if hint and hint not in normalized.setdefault(normalized_route, []):
|
||||
normalized[normalized_route].append(hint)
|
||||
|
||||
hints: list[str] = []
|
||||
for raw_route in ("all", route):
|
||||
for hint in normalized.get(raw_route, []):
|
||||
if hint not in hints:
|
||||
hints.append(hint)
|
||||
return hints
|
||||
|
||||
|
||||
def merge_position_keys(primary: list[str], fallback: list[str]) -> list[str]:
|
||||
merged: list[str] = []
|
||||
for key in [*primary, *fallback]:
|
||||
|
||||
Reference in New Issue
Block a user