Fix SyntaxWarning on Python 3.12+: use raw string for mountain_regex#12
Open
sree-vahn wants to merge 1 commit into
Open
Fix SyntaxWarning on Python 3.12+: use raw string for mountain_regex#12sree-vahn wants to merge 1 commit into
sree-vahn wants to merge 1 commit into
Conversation
The regex contains escape sequences like \w that are invalid in a regular string literal. Python 3.12 surfaces this as a SyntaxWarning on every run, and it is slated to become a SyntaxError in a future Python release. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019xSXfPHE79nquz7yRgb5ku
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
mountain_regexinsrc/path_to_enlightenment.pyis defined as a regular string literal containing regex escape sequences (\w,\-,\(,\)), which are invalid escape sequences at the Python string level:On Python 3.12 and newer, every run of the koans prints:
This is confusing for learners — the warning contains the word "invalid" and appears right before the koan output, so it's easy to mistake for a failing koan.
Why this shows up now
DeprecationWarning(hidden by default).SyntaxWarning, shown by default (What's New in Python 3.12).SyntaxError, at which point the koans would stop running entirely.Fix
Make the pattern a raw string (one-character change). The regex itself is unchanged —
rereceives the exact same pattern as before, so behavior is identical on all Python versions, and the project stays compatible with Python 2 as documented.Verified by running
python3 src/path_to_enlightenment.pyon Python 3.12.10: the warning is gone and the koans behave exactly as before.🤖 Generated with Claude Code
https://claude.ai/code/session_019xSXfPHE79nquz7yRgb5ku