mchaput / whoosh

Pure-Python full-text search library
Other
569 stars 69 forks source link

[chore] fix "SyntaxError: invalid escape sequence" #45

Open jmelahman opened 1 year ago

jmelahman commented 1 year ago

If you use this library with PYTHONWARNINGS=error::DeprecationWarning, you are met with the following error,

File ".../whoosh/analysis/filters.py", line 50
--
  | url_pattern = rcompile("""
  | ^
  | SyntaxError: invalid escape sequence \w
--

This change was purely mechanical; I ran ruff check --fix --select W605 on the repository, https://beta.ruff.rs/docs/rules/#warning-w.


==================================================== 587 passed in 8.58s =====================================================
.pkg: _exit> python /usr/lib/python3.11/site-packages/pyproject_api/_backend.py True setuptools.build_meta __legacy__
  py27: SKIP (0.01 seconds)
  py33: SKIP (0.00 seconds)
  py34: SKIP (0.00 seconds)
  py35: SKIP (0.00 seconds)
  py36: SKIP (0.00 seconds)
  py37: OK (15.99=setup[7.18]+cmd[8.81] seconds)
  congratulations :) (16.06 seconds)

You can also repro the errors with the following diff

diff --git a/tox.ini b/tox.ini
index bf5bfd6..34aa21c 100644
--- a/tox.ini
+++ b/tox.ini
@@ -1,8 +1,8 @@
 [tox]
-envlist = py27, py33, py34, py35, py36, py37
+envlist = py27, py33, py34, py35, py36, py37, py39

 [testenv]
 deps =
        pytest
        pytest-pep8
-commands = py.test -s {posargs} tests
+commands = py.test -W error::DeprecationWarning -s {posargs} tests

which yields,

__________________________________________ ERROR collecting tests/test_analysis.py ___________________________________________
.tox/py39/lib/python3.9/site-packages/_pytest/python.py:617: in _importtestmodule
    mod = import_path(self.path, mode=importmode, root=self.config.rootpath)
.tox/py39/lib/python3.9/site-packages/_pytest/pathlib.py:565: in import_path
    importlib.import_module(module_name)
/usr/lib/python3.9/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:1030: in _gcd_import
    ???
<frozen importlib._bootstrap>:1007: in _find_and_load
    ???
<frozen importlib._bootstrap>:986: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:680: in _load_unlocked
    ???
.tox/py39/lib/python3.9/site-packages/_pytest/assertion/rewrite.py:169: in exec_module
    source_stat, co = _rewrite_test(fn, self.config)
.tox/py39/lib/python3.9/site-packages/_pytest/assertion/rewrite.py:351: in _rewrite_test
    tree = ast.parse(source, filename=strfn)
/usr/lib/python3.9/ast.py:50: in parse
    return compile(source, filename, mode, flags,
E     File "/home/jamison/code/third-party/whoosh/tests/test_analysis.py", line 523
E       t = analysis.RegexTokenizer("\w+")
E                                   ^
E   SyntaxError: invalid escape sequence \w