Skip to content

Conversation

stabbotco1
Copy link

Problem

When running contemplate_koans.py on Python 3.8+, the following warnings appear:

❯ python3 contemplate_koans.py
/Users/user1/projects/python_koans/runner/sensei.py:63: SyntaxWarning: invalid escape sequence '\d'
m = re.search("(?<= line )\d+" ,err)
/Users/user1/projects/python_koans/runner/sensei.py:149: SyntaxWarning: invalid escape sequence '\w'
m = re.search("^ \w(\w)+.*$",line)

These warnings occur because \d and \w are special escape sequences in regular expressions, and Python expects them to be inside a raw string literal (r"pattern") or properly escaped ("\d").
Fix

Converted the affected regex patterns into raw string literals (r"pattern") to prevent Python from misinterpreting escape sequences:

Before (causing warnings):

m = re.search("(?<= line )\d+" ,err)
m = re.search("^ \w(\w)+.*$",line)

After (fixed with raw strings):

m = re.search(r"(?<= line )\d+" ,err)
m = re.search(r"^ \w(\w)+.*$",line)

Impact

Removes SyntaxWarning messages in Python 3.8+.
Improves regex compatibility across different Python versions.
No changes to logic or functionality.

Let me know if any additional changes are needed! 🚀

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