ftrackhq / ftrack-python

Python API for ftrack
Apache License 2.0
3 stars 1 forks source link

SyntaxWarnings related to invalid escape sequences when installing by Poetry #51

Open Cybernetic-Ransomware opened 1 month ago

Cybernetic-Ransomware commented 1 month ago

Hi, recently tried to instal library by poetry. That started some background validations processes. So, right now i have a list of SyntaxWarning prints during stetting the containers. All of them are about invalid escape sequence. I think that could be simply fixed by raw string synthax: r'', but i wonder, did someone met inproper functionalities during the rular usage?

Hi,

I recently tried to install the library using Poetry, which triggered some background validation processes. Currently, I am encountering a list of SyntaxWarningmessages related to invalid escape sequences while setting up the containers. All of the warnings are about invalid escape sequences:

app-1            | /usr/local/lib/python3.12/site-packages/ftrack_api/query.py:13: SyntaxWarning: invalid escape sequence '\d'
app-1            |   OFFSET_EXPRESSION = re.compile("(?P<offset>offset (?P<value>\d+))")
app-1            | /usr/local/lib/python3.12/site-packages/ftrack_api/query.py:14: SyntaxWarning: invalid escape sequence '\d'                                                                                                                                                                                     
app-1            |   LIMIT_EXPRESSION = re.compile("(?P<limit>limit (?P<value>\d+))")                                                                                                                                                                                                                              
app-1            | /usr/local/lib/python3.12/site-packages/ftrack_api/query.py:13: SyntaxWarning: invalid escape sequence '\d'                                                                                                                                                                                     
app-1            |   OFFSET_EXPRESSION = re.compile("(?P<offset>offset (?P<value>\d+))")
app-1            | /usr/local/lib/python3.12/site-packages/ftrack_api/query.py:14: SyntaxWarning: invalid escape sequence '\d'                                                                                                                                                                                     
app-1            |   LIMIT_EXPRESSION = re.compile("(?P<limit>limit (?P<value>\d+))")                                                                                                                                                                                                                              
app-1            | /usr/local/lib/python3.12/site-packages/ftrack_api/query.py:13: SyntaxWarning: invalid escape sequence '\d'                                                                                                                                                                                     
app-1            |   OFFSET_EXPRESSION = re.compile("(?P<offset>offset (?P<value>\d+))")
app-1            | /usr/local/lib/python3.12/site-packages/ftrack_api/query.py:14: SyntaxWarning: invalid escape sequence '\d'                                                                                                                                                                                     
app-1            |   LIMIT_EXPRESSION = re.compile("(?P<limit>limit (?P<value>\d+))")                                                                                                                                                                                                                              
app-1            | /usr/local/lib/python3.12/site-packages/ftrack_api/plugin.py:32: SyntaxWarning: invalid escape sequence '\*'
app-1            |   """Find and load plugins in search *paths*.
app-1            | /usr/local/lib/python3.12/site-packages/ftrack_api/structure/standard.py:133: SyntaxWarning: invalid escape sequence '\w'                                                                                                                                                                       
app-1            |   "[^\w\.-]", self.illegal_character_substitute, value.decode("utf-8")
app-1            | /usr/local/lib/python3.12/site-packages/ftrack_api/structure/standard.py:133: SyntaxWarning: invalid escape sequence '\w'                                                                                                                                                                       
app-1            |   "[^\w\.-]", self.illegal_character_substitute, value.decode("utf-8")                                                                                                                                                                                                                          
app-1            | /usr/local/lib/python3.12/site-packages/ftrack_api/structure/standard.py:133: SyntaxWarning: invalid escape sequence '\w'                                                                                                                                                                       
app-1            |   "[^\w\.-]", self.illegal_character_substitute, value.decode("utf-8")
app-1            | /usr/local/lib/python3.12/site-packages/ftrack_api/structure/standard.py:133: SyntaxWarning: invalid escape sequence '\w'                                                                                                                                                                       
app-1            |   "[^\w\.-]", self.illegal_character_substitute, value.decode("utf-8")        

I believe this could be easily fixed by using raw string syntax (r''), but I wonder if anyone has experienced any functionality issues related to this during regular usage?

stat1c-void commented 6 days ago

Same. Those affected strings definitely should be prefixed with raw modifier.

Not necessarily needs to be installed through Poetry in order to reproduce the warnings. Checked with Python versions: 3.10.15, 3.11.10.

Reproduction steps

docker run --rm -it python:3.11-slim bash

# inside the container:
pip install --no-compile ftrack-python-api
python -B -Wall -c "import ftrack_api"

--no-compile seems important for reproduction, because pip might mask those warnings.

Output:

/usr/local/lib/python3.11/site-packages/ftrack_api/query.py:13: DeprecationWarning: invalid escape sequence '\d'
  OFFSET_EXPRESSION = re.compile("(?P<offset>offset (?P<value>\d+))")
/usr/local/lib/python3.11/site-packages/ftrack_api/query.py:14: DeprecationWarning: invalid escape sequence '\d'
  LIMIT_EXPRESSION = re.compile("(?P<limit>limit (?P<value>\d+))")
/usr/local/lib/python3.11/site-packages/pyparsing.py:108: DeprecationWarning: module 'sre_constants' is deprecated
  import sre_constants
/usr/local/lib/python3.11/site-packages/ftrack_api/plugin.py:32: DeprecationWarning: invalid escape sequence '\*'
  """Find and load plugins in search *paths*.
/usr/local/lib/python3.11/site-packages/ftrack_api/structure/standard.py:133: DeprecationWarning: invalid escape sequence '\w'
  "[^\w\.-]", self.illegal_character_substitute, value.decode("utf-8")

Those aren't the only problematic strings in the codebase. Somewhat crude regexp grep of the codebase yields the following:

test/unit/test_plugin.py
73:    output = re.sub("(\w+)=\w+", '"\g<1>={}".format(\g<1>)', specification)
74:    output = re.sub("\*args", "args", output)
75:    output = re.sub("\*\*kwargs", "sorted(kwargs.items())", output)