Skip to content

Fix invalid \\] escape sequence in conversation.py regex#27

Open
tundakk wants to merge 1 commit intotechartdev:mainfrom
tundakk:fix/conversation-syntax-warning
Open

Fix invalid \\] escape sequence in conversation.py regex#27
tundakk wants to merge 1 commit intotechartdev:mainfrom
tundakk:fix/conversation-syntax-warning

Conversation

@tundakk
Copy link
Copy Markdown

@tundakk tundakk commented May 7, 2026

Summary

The regex literal at custom_components/openclaw/conversation.py:316 is parsed by Python as two adjacent string literals rather than one. The second of those literals is non-raw and contains \], which Python 3.12+ flags as SyntaxWarning: invalid escape sequence '\]' and which Python 3.14 promotes to SyntaxError.

# Before — splits into r"\?\s*[\"'" + "»)\]]*\s*$" because the inner "" closes
# the raw string and reopens a non-raw one. The non-raw half then contains \].
if re.search(r"\?\s*[\"'""»)\]]*\s*$", text):

# After — single raw string, identical regex semantics.
if re.search(r"\?\s*[\"'»)\]]*\s*$", text):

The compiled regex character class is identical (["'»)\]]); only the Python source representation changes. The redundant inner "" was a no-op concatenation seam, not a deliberate character.

Verification

  • python -W error::SyntaxWarning -c "import py_compile; py_compile.compile('conversation.py', doraise=True)" — passes after the fix, fails before.
  • Regex still matches Are you sure?, Are you sure? ", Are you sure? », Are you sure?) and rejects Statement. (verified locally).
  • One-line change, scoped to a cosmetic style fix; orthogonal to PR conversation: scrub OpenClaw tool_code fences before TTS #26 (behavioral scrubber change).

Test plan

  • CI / maintainer's local Python ≥ 3.12 no longer emits the SyntaxWarning on import of conversation.py.
  • No behavior change in _is_likely_question_followup follow-up detection.

…thon 3.12+ raises SyntaxWarning (3.14 SyntaxError) on the regex literal at conversation.py:316; the pattern was two adjacent string literals where the second was non-raw and contained \]. Consolidating into a single raw string preserves regex semantics.

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant