From: Jérôme Benoit Date: Sun, 21 Jun 2026 20:37:10 +0000 (+0200) Subject: fix(quickadapter): restore _format_collection ordering before register decorators X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=6727bd127a7b6d3ae6faf78c134a46a5b4054559;p=freqai-strategies.git fix(quickadapter): restore _format_collection ordering before register decorators Rebase of the label-weight-support-policy PR onto main (atop the style line-wrap commit) reapplied the _format_collection hunk at the wrong location, placing the helper AFTER its @_format_value.register(list|tuple|set|dict|np.ndarray) decorators. Move the definition back to its canonical position above the dispatchers. --- diff --git a/quickadapter/user_data/strategies/Utils.py b/quickadapter/user_data/strategies/Utils.py index cbbc3d6..0bd4f0f 100644 --- a/quickadapter/user_data/strategies/Utils.py +++ b/quickadapter/user_data/strategies/Utils.py @@ -2134,6 +2134,33 @@ def _(value: str, ctx: _FormatContext, depth: int) -> str: return escaped +def _format_collection( + value: list | tuple | set, + ctx: _FormatContext, + depth: int, + brackets: tuple[str, str], + empty: str, + trailing_comma: bool = False, +) -> str: + if not value: + return empty + obj_id = id(value) + if obj_id in ctx.seen: + return f"{brackets[0]}{brackets[1]}" + if depth >= _MAX_DEPTH: + return f"{brackets[0]}...{brackets[1]}" + ctx.seen.add(obj_id) + items_iter = sorted(value, key=str) if isinstance(value, set) else value + items = [_format_value(v, ctx, depth + 1) for v in list(items_iter)[:_MAX_ITEMS]] + if len(value) > _MAX_ITEMS: + items.append(f"...+{len(value) - _MAX_ITEMS}") + content = ", ".join(items) + if trailing_comma and len(value) == 1 and len(items) == 1: + content += "," + ctx.seen.discard(obj_id) + return f"{brackets[0]}{content}{brackets[1]}" + + @_format_value.register(list) def _(value: list, ctx: _FormatContext, depth: int) -> str: return _format_collection(value, ctx, depth, ("[", "]"), "[]") @@ -2175,33 +2202,6 @@ def _(value: np.ndarray, ctx: _FormatContext, depth: int) -> str: return f"array{value.shape}" -def _format_collection( - value: list | tuple | set, - ctx: _FormatContext, - depth: int, - brackets: tuple[str, str], - empty: str, - trailing_comma: bool = False, -) -> str: - if not value: - return empty - obj_id = id(value) - if obj_id in ctx.seen: - return f"{brackets[0]}{brackets[1]}" - if depth >= _MAX_DEPTH: - return f"{brackets[0]}...{brackets[1]}" - ctx.seen.add(obj_id) - items_iter = sorted(value, key=str) if isinstance(value, set) else value - items = [_format_value(v, ctx, depth + 1) for v in list(items_iter)[:_MAX_ITEMS]] - if len(value) > _MAX_ITEMS: - items.append(f"...+{len(value) - _MAX_ITEMS}") - content = ", ".join(items) - if trailing_comma and len(value) == 1 and len(items) == 1: - content += "," - ctx.seen.discard(obj_id) - return f"{brackets[0]}{content}{brackets[1]}" - - def format_dict( d: dict[str, Any], style: Literal["dict", "params"] = "dict",