Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SyntaxWarning by using a raw string in the regex pattern #366

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tsvikas
Copy link

@tsvikas tsvikas commented Jan 20, 2025

Problem

The previous code emitted the following warning:

site-packages/jupyterlab_code_formatter/formatters.py:110: SyntaxWarning: invalid escape sequence '\s'

Cause

This warning occurred because Python treats \ as an escape character unless the string is marked as raw (using the r"" prefix) or the escape sequence is invalid. In this case, the intention was to pass \s and \w to the regex pattern. Although the regex received the correct pattern, the warning indicates a potential issue.

Solution

To address this, the string has been updated to use a raw string (e.g., r"run\s+\w+"). This approach

  • Explicitly indicates that \ is part of the regex pattern.
  • Prevents the warning.
  • Makes the code more robust against new escape codes or future changes to the regex pattern.

set a string to raw. it is used in a regex, and the \ should be escaped to be visible to the regex.
Copy link

Binder 👈 Launch a Binder on branch tsvikas/jupyterlab_code_formatter/patch-1

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