Skip to content

[Bug]: f-string expression part cannot include a backslash in preview.py #372

Description

@carry-xz

Affected Software/Harness

cli-hub

Version / Commit

latest (main branch commit: dc73924)

Operating System

macOS

Python Version

3.10+

Steps to Reproduce

  1. Install cli-hub: pip install cli-anything-hub
  2. Run: cli-hub list
  3. See SyntaxError occur

Expected Behavior

The cli-hub list command should execute successfully and display the list of available CLIs.

Actual Behavior

A SyntaxError is raised during module import:

SyntaxError: f-string expression part cannot include a backslash

The error prevents the entire cli-hub CLI from loading.

Relevant Logs / Tracebacks

Traceback (most recent call last):
  File "/opt/homebrew/bin/cli-hub", line 3, in <module>
    from cli_hub.cli import main
  File "/opt/homebrew/lib/python3.10/site-packages/cli_hub/cli.py", line 46, in <module>
    from cli_hub.preview import (
  File "/opt/homebrew/lib/python3.10/site-packages/cli_hub/preview.py", line 725
    )
    ^
SyntaxError: f-string expression part cannot include a backslash

Additional Context

Root Cause:
In cli-hub/cli_hub/preview.py line 723, the _render_trajectory_html_section() function contains an f-string with escaped quotes in the expression:

f'<div class="trajectory-list">{items_html or "<div class=\"artifact-file\">No step timeline entries yet.</div>"}</div>'

Python 3.10+ prohibits backslashes inside f-string expression curly braces {}.

Fix:
Extract the nested HTML string to a variable before using it in the f-string:

empty_message = '<div class="artifact-file">No step timeline entries yet.</div>'
items_html = "..."  # existing computation

return (
    '<section class="section">'
    "<h2>Trajectory</h2>"
    f'<div class="facts">{cards_html}</div>'
    f'<div class="trajectory-list">{items_html or empty_message}</div>'
    "</section>"
)

This maintains full functionality while avoiding backslashes in f-string expressions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions