Skip to content

Escape backslashes in coe.py and text.py string literals - #726

Merged
qtuantruong merged 1 commit into
PreferredAI:masterfrom
MBK-fr:fix/invalid-escape-sequence-syntaxwarning
Sep 13, 2026
Merged

qtuantruong merged 1 commit into
PreferredAI:masterfrom
MBK-fr:fix/invalid-escape-sequence-syntaxwarning

Conversation

@MBK-fr

@MBK-fr MBK-fr commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

Problem

Cornac has two non-raw string literals with unrecognised escapes: \s in cornac/models/coe/coe.py and \] in cornac/data/text.py. Importing either module under Python 3.12+ raises SyntaxWarning: invalid escape sequence.

Why it matters for Cornac

setup/packaging declares requires-python >=3.10 and CI exercises 3.10 through 3.13, so the 3.12/3.13 runs emit these warnings when the affected modules are loaded.

Fix

Add the missing backslash in each literal (\s -> \\s, \] -> \\]). The decoded string is byte-for-byte the same; only the deprecation-path warning goes away. Equivalent to ruff's W605 fix.

How I checked

Verified with python3 -W error -m py_compile (raises before, clean after) and by diffing ast.dump() of each module before and after the change - no AST difference.


🤖 Generated with Claude Code

https://claude.ai/code/session_014HBQNzAf5C2E3MiJC48HQw

cornac/models/coe/coe.py (a `\s`) and cornac/data/text.py (a `\]`)
contain invalid escape sequences in non-raw strings, which raise
`SyntaxWarning: invalid escape sequence` on Python 3.12+. Cornac's CI
runs 3.10 through 3.13. Escaping the backslashes preserves the values.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014HBQNzAf5C2E3MiJC48HQw

@qtuantruong qtuantruong left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks

@qtuantruong
qtuantruong merged commit 8cd3cdf into PreferredAI:master Sep 13, 2026
1 check passed
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.

2 participants