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 invalid escape sequences, noisy since py3.12, deprecated since py3.6 #22

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

Conversation

zer0def
Copy link

@zer0def zer0def commented Jan 1, 2025

Fixes invalid escape sequences, which were deprecated since py3.6 and started raising SyntaxWarnings since py3.12, example follows.

python: stdout/stderr (?): /home/user/.weechat/python/twitch.py:354: SyntaxWarning: invalid escape sequence '\s'
python: stdout/stderr (?):   bn=tags['ban-reason'].replace('\s',' ')
python: stdout/stderr (?): /home/user/.weechat/python/twitch.py:362: SyntaxWarning: invalid escape sequence '\s'
python: stdout/stderr (?):   bn=tags['ban-reason'].replace('\s',' ')
python: stdout/stderr (?): /home/user/.weechat/python/twitch.py:459: SyntaxWarning: invalid escape sequence '\s'
python: stdout/stderr (?):   msg = tags['system-msg'].replace('\s',' ')

Upstream references:

@mumixam
Copy link
Owner

mumixam commented Jan 4, 2025

Thanks for reporting.
I'm running a older version of python3 so i havent noticed this yet.

I went ahead and tested with 3.12 but i made of the change of changing replace('\s',' ') to replace(r'\s',' ') it seems to fix the issue. Looks like twitch doesn't announce the reason for the ban anymore via irc tags anyway but i tested in my own channel banning a user that wasn't in the chat. Did you happen to test with replace(r'\s',' ') and have issues?

@zer0def
Copy link
Author

zer0def commented Jan 4, 2025

I have, it made the warnings go away, but no longer performed the substitution. At best, it's the same kind of no-op, as it is before this change.

$ python
Python 3.13.1 (main, Dec  4 2024, 18:05:56) [GCC 14.2.1 20240910] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import re; a = '\t'
>>> ' '.replace(r' ', 'a')
'a'
>>> a.replace(r'\s', 'a')
'\t'
>>> a.replace(r'\\s', 'a')
'\t'
>>> re.sub(r'\s', 'a', a)
'a'

@zer0def zer0def force-pushed the py3.12-syntaxwarning-re branch from 44bcde3 to c086533 Compare January 7, 2025 23:40
@zer0def
Copy link
Author

zer0def commented Jan 7, 2025

Updated handling on the system-msg tag, as it turns out to have it's string delimited by raw \s substring, not a whitespace matcher.

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