xcsp3team / pycsp3

A Python Library for modeling combinatorial constrained problems
https://www.pycsp.org
MIT License
60 stars 9 forks source link

Suspicious escape sequences in some regular expressions #49

Open wjsuijlenh opened 1 month ago

wjsuijlenh commented 1 month ago

After removing any *.pyc file from the repository so that Python is forced to parse everything again, Python 3.12.4 displays some warnings about suspicious use of escape sequences in some of the regular expressions. This is on commit 67ff8626096715bd6fc885612ed227b503fcaac9

I guess the original intention was to use Python's raw string notation?

[...]/pycsp3/classes/entities.py:313: SyntaxWarning: invalid escape sequence '\]'
  indexes = [int(v) if len(v) > 0 else None for v in re.split("\]\[", suffix[1:-1])]
[...]/pycsp3/classes/main/variables.py:199: SyntaxWarning: invalid escape sequence '\]'
  self.indexes = [int(v) for v in re.split("\]\[", self.suffix[1:-1])]
[...]/gitrepo/pycsp3/tools/aggregator.py:156: SyntaxWarning: invalid escape sequence '\d'
  if par not in re.findall('(%\d+)', abstract_tree):
[...]/gitrepo/pycsp3/tools/aggregator.py:157: SyntaxWarning: invalid escape sequence '\d'
  t = {int(m[1:]) for m in re.findall('(%\d+)', abstract_tree) if int(m[1:]) > i}
[...]/pycsp3/tools/compactor.py:17: SyntaxWarning: invalid escape sequence '\]'
  self.starts = [int(v) for v in re.split("\]\[", self.suffix[1:-1])]  # the indexes of the first variable (in case of an array)
[...]/pycsp3/tools/compactor.py:187: SyntaxWarning: invalid escape sequence '\]'
  tokens = [int(v) if v.isdigit() else v for v in re.split("\]\[", suffix[1:-1])]
[...]/pycsp3/tools/compactor.py:222: SyntaxWarning: invalid escape sequence '\]'
  part = sorted(part, key=lambda x: [int(v) for v in re.split("\]\[", x.id[x.id.index("[") + 1:-1])])
xcsp3team commented 1 month ago

Thanks for the issue. Expressions have been updated (and pushed)