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 on regex invalid escape sequences #69

Merged
merged 1 commit into from
Oct 3, 2024

Conversation

alanswanson
Copy link

Use raw string for regex with escape sequences. Was previously a silent DeprecationWarning but with Python 3.12 it becomes a SyntaxWarning and for future Python releases it will become a SyntaxError.

2024-09-26 22:01:28.483 T:7003    error <general>: /home/kodi/.kodi/addons/script.xbmc.lcdproc/resources/lib/lcdproc.py
2024-09-26 22:01:28.483 T:7003    error <general>: :283:
2024-09-26 22:01:28.483 T:7003    error <general>: SyntaxWarning
2024-09-26 22:01:28.483 T:7003    error <general>: :
2024-09-26 22:01:28.483 T:7003    error <general>: invalid escape sequence '\.'
2024-09-26 22:01:28.483 T:7003    error <general>:

2024-09-26 22:01:28.484 T:7003    error <general>:
2024-09-26 22:01:28.485 T:7003    error <general>: lcdinfo = re.match("^connect .+ protocol ([0-9\.]+) lcd wid (\d+) hgt (\d+) cellwid (\d+) cellhgt (\d+)$", reply)
2024-09-26 22:01:28.485 T:7003    error <general>:

2024-09-26 22:01:28.517 T:7003    error <general>: /home/kodi/.kodi/addons/script.xbmc.lcdproc/resources/lib/lcdbase.py:385: SyntaxWarning: invalid escape sequence '\d'
                                                     timeregex = r'' + re.escape('$INFO[LCD.') + 'Time((Wide)?\d?\d?)' + re.escape(']')

2024-09-26 22:01:28.517 T:7003    error <general>: /home/kodi/.kodi/addons/script.xbmc.lcdproc/resources/lib/lcdbase.py:433: SyntaxWarning: invalid escape sequence '\s'
                                                     linedescriptor['text'] = re.sub(r'\s?' + re.escape("$INFO[LCD.PlayIcon]") + '\s?', ' ', linetext, flags=re.IGNORECASE).strip()

2024-09-26 22:01:28.517 T:7003    error <general>: /home/kodi/.kodi/addons/script.xbmc.lcdproc/resources/lib/lcdbase.py:446: SyntaxWarning: invalid escape sequence '\s'
                                                     linedescriptor['text'] = re.sub(r'\s?' + re.escape("$INFO[LCD.AlignCenter]") + '\s?', ' ', linedescriptor['text'], flags=re.IGNORECASE).strip()

2024-09-26 22:01:28.517 T:7003    error <general>: /home/kodi/.kodi/addons/script.xbmc.lcdproc/resources/lib/lcdbase.py:447: SyntaxWarning: invalid escape sequence '\s'
                                                     linedescriptor['text'] = re.sub(r'\s?' + re.escape("$INFO[LCD.AlignRight]") + '\s?', ' ', linedescriptor['text'], flags=re.IGNORECASE).strip()

2024-09-26 22:01:28.518 T:7003    error <general>: /home/kodi/.kodi/addons/script.xbmc.lcdproc/resources/lib/lcdbase.py:494: SyntaxWarning: invalid escape sequence '\['
                                                     regexbbcode = "\[(?P<tagname>[0-9a-zA-Z_\-]+?)[0-9a-zA-Z_\- ]*?\](?P<content>.*?)\[\/(?P=tagname)\]"

2024-09-26 22:01:28.518 T:7003    error <general>: /home/kodi/.kodi/addons/script.xbmc.lcdproc/resources/lib/lcdbase.py:513: SyntaxWarning: invalid escape sequence '\g'
                                                     mangledline, replacements = re.subn(self.m_reBBCode, "\g<content>", mangledline)

Only logged on initial compile of pycache so need to delete ~/.kodi/addons/script.xbmc.lcdproc/resources/lib/__pycache__/ to (re)observe.

Use raw string for regex with escape sequences. Was previously a
silent DeprecationWarning but with Python 3.12 it becomes a
SyntaxWarning and for future Python releases it will become a
SyntaxError.
@herrnst
Copy link
Owner

herrnst commented Sep 27, 2024

Thanks, good catch. Will quick-test a few things the next days (time is a bit limited right now).

@herrnst
Copy link
Owner

herrnst commented Oct 3, 2024

SyntaxWarning confirmed after deleting pycache's, fixed by your change and didn't notice any breakage. Merging as-is, thank you very much!

@herrnst herrnst merged commit 157a06c into herrnst:master Oct 3, 2024
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.

2 participants