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

[BUG] results.py:100: SyntaxWarning: invalid escape sequence '\|' #1144

Open
6 tasks
glitsj16 opened this issue Apr 27, 2024 · 0 comments
Open
6 tasks

[BUG] results.py:100: SyntaxWarning: invalid escape sequence '\|' #1144

glitsj16 opened this issue Apr 27, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@glitsj16
Copy link
Contributor

glitsj16 commented Apr 27, 2024

Describe the bug
Getting the below warning on Arch Linux with Python 3.12:

Apr 27 18:53:23 lab16 whoogle[4699: /home/glitsj16/whoogle-search/app/utils/results.py:100: SyntaxWarning: invalid escape sequence '\|'
Apr 27 18:53:23 lab16 whoogle[4699:   if re.match('.*[@_!#$%^&*()<>?/\|}{~:].*', target_word) or (

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Deployment Method

  • Heroku (one-click deploy)
  • Docker
  • [x ] run executable
  • pip/pipx
  • Other: [describe setup]

Version of Whoogle Search

  • [ x] Latest build from [source] (i.e. GitHub, Docker Hub, pip, etc)
  • Version [version number]
  • Not sure

Desktop (please complete the following information):

  • OS: Arch Linux
  • Browser Firefox
  • Version 125.0.2-1

Smartphone (please complete the following information):

  • Device: N/A
  • OS: N/A
  • Browser N/A
  • Version N/A

Additional context
Add any other context about the problem here.

$ pacman -Q python
python 3.12.3-1

This small patch fixes the warning for me, but this is python 3.12 so there's probably a better way to deal with the warning:

UPDATE:
This is due to the fact that Python 3.12.3 does SyntaxWarning instead of DeprecationWarning for invalid backslash escape sequences:

Invalid backslash escape sequences in strings now warn with SyntaxWarning instead of DeprecationWarning, making them more visible. (They will become syntax errors in the future.)

Using a raw string for matching regex fixes things:

$ cat syntaxwarning.patch
--- a/app/utils/results.py
+++ b/app/utils/results.py
@@ -97,7 +97,7 @@
         else:
             reg_pattern = fr'\b((?![{{}}<>-]){target_word}(?![{{}}<>-]))\b'
 
-        if re.match('.*[@_!#$%^&*()<>?/\|}{~:].*', target_word) or (
+        if re.match(r'.*[@_!#$%^&*()<>?/\|}{~:].*', target_word) or (
                 element.parent and element.parent.name == 'style'):
             return

HTH

@glitsj16 glitsj16 added the bug Something isn't working label Apr 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant