Skip to content

Issue #208 Fix "invalid escape sequence" warnings before they become errors #209

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

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

Conversation

Rob-S
Copy link

@Rob-S Rob-S commented May 13, 2025

Issue #208 Fix "invalid escape sequence" warnings before they become errors

Description

Escape "\" in regular expressions. A single backslash "\" is the Python escape character. To code the escape character "\" in regular expressions, the backslash itself needs to be escaped as "\\".

Motivation and Context

Per https://docs.python.org/3/library/re.html, the "invalid escape sequence" Syntax Warning will become a Syntax Error in a future version of Python:

Please note that any invalid escape sequences in Python’s usage of the backslash in string literals now generate a SyntaxWarning and in the future this will become a SyntaxError.

Specifically, this PR corrects the cause of the following Syntax Warning messages, so that they will not cause a failure when Python is updated and they become Syntax Errors.

/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/ask_sdk_core/serialize.py:191: SyntaxWarning: invalid escape sequence '\['
  'list\[(.*)\]', obj_type)
/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/ask_sdk_core/serialize.py:212: SyntaxWarning: invalid escape sequence '\('
  'dict\(([^,]*), (.*)\)', obj_type)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project
  • My change requires a change to the documentation
  • I have updated the documentation accordingly
  • I have read the README document
  • I have added tests to cover my changes
  • All new and existing tests passed

License

  • By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@Rob-S
Copy link
Author

Rob-S commented May 13, 2025

An alternative would be to use raw strings (r'...') it that would be preferred.

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