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

SyntaxWarning in the console for invalid escape sequences. #39

Open
mattcoleanderson opened this issue Oct 24, 2023 · 1 comment
Open

Comments

@mattcoleanderson
Copy link

mattcoleanderson commented Oct 24, 2023

In Autodoist 2.0 the following is logged in the console:

docker run -it mattcoleanderson/autodoist
/usr/src/app/./autodoist.py:686: SyntaxWarning: invalid escape sequence '\s'
  regex_a = '(^[*]{2}\s*)(.*)'
/usr/src/app/./autodoist.py:687: SyntaxWarning: invalid escape sequence '\-'
  regex_b = '(^\-\*\s*)(.*)'
/usr/src/app/./autodoist.py:1369: SyntaxWarning: invalid escape sequence '\d'
  'start=(\d{2}[-]\d{2}[-]\d{4})', task.content)
/usr/src/app/./autodoist.py:1392: SyntaxWarning: invalid escape sequence '\d'
  'start=due-(\d+)([dw])', task.content)

This SyntaxWarning occurs because Python attempts to evaluate escape sequences in string literals. However, regex has many uses for backslashes that aren't valid escape sequences.

We can get rid of this SyntaxWarning by prepending the string literal with an r. This makes a "raw string" which tells python to interpret the string literally.

@mattcoleanderson
Copy link
Author

mattcoleanderson commented Oct 24, 2023

I've gone ahead and opened a quick PR to prepend "r" to the 4 regex strings causing the Syntax Warning.

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 a pull request may close this issue.

1 participant