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

Use raw strings for regexes; fixes SyntaxWarning: invalid escape sequence #486

Merged
merged 1 commit into from
Sep 13, 2024

Conversation

dlitz
Copy link
Contributor

@dlitz dlitz commented Sep 12, 2024

When running gw --help for the first time under Python 3.12, I get a bunch of warnings:


.../src/greaseweazle/tools/util.py:103: SyntaxWarning: invalid escape sequence '\d'
  m = re.match('(\d*\.\d+|\d+)rpm', arg)
.../src/greaseweazle/tools/util.py:106: SyntaxWarning: invalid escape sequence '\d'
  m = re.match('(\d*\.\d+|\d+)ms', arg)
.../src/greaseweazle/tools/util.py:109: SyntaxWarning: invalid escape sequence '\d'
  m = re.match('(\d*\.\d+|\d+)us', arg)
.../src/greaseweazle/tools/util.py:112: SyntaxWarning: invalid escape sequence '\d'
  m = re.match('(\d*\.\d+|\d+)ns', arg)
.../src/greaseweazle/tools/util.py:115: SyntaxWarning: invalid escape sequence '\d'
  m = re.match('(\d*\.\d+|\d+)scp', arg)
.../src/greaseweazle/tools/util.py:193: SyntaxWarning: invalid escape sequence '\d'
  m = re.match('(\d+)(-(\d+)(/(\d+))?)?$', crange)
.../src/greaseweazle/tools/util.py:220: SyntaxWarning: invalid escape sequence '\d'
  m = re.match('([+-]\d+)$', v)
.../src/greaseweazle/tools/util.py:224: SyntaxWarning: invalid escape sequence '\d'
  m = re.match('1/(\d+)$', v)
  info        Display information about the Greaseweazle setup.
.../src/greaseweazle/codec/codec.py:217: SyntaxWarning: invalid escape sequence '\s'
  '\s+([\w,.-]+)', t)
.../src/greaseweazle/codec/codec.py:236: SyntaxWarning: invalid escape sequence '\.'
  '(?:\.([01]))?', x)
.../src/greaseweazle/codec/codec.py:264: SyntaxWarning: invalid escape sequence '\s'
  '\s*([a-zA-Z0-9:,._-]+)', t)
.../src/greaseweazle/codec/codec.py:283: SyntaxWarning: invalid escape sequence '\s'
  '\s*([a-zA-Z0-9:,._*-]+)', t)

This doesn't happen when loading the cached .pyc files, so to reproduce the original problem, remove the __pycache__ directories before running gw.

This pull request fixes these errors by using raw strings (r'foo\d' instead of 'foo\d').

@keirf keirf merged commit f139f46 into keirf:master Sep 13, 2024
4 checks passed
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