Skip to content
  • muxator's avatar
    py3: use raw strings in regular expressions literals that contain backslashes · 84ca27b0f478
    muxator authored
    The problem was already present with python versions <= 3.11, but only appeared
    at runtime. From python 3.12 onwards it becomes possible to statically reproduce
    it by forcing a bytecode compilation.
    
    The change is useful for future-proofing the code base, since future python
    versions will start to exit with a runtime exception.
    
    From https://docs.python.org/3/whatsnew/3.12.html#other-language-changes :
        A backslash-character pair that is not a valid escape sequence now generates
        a SyntaxWarning, instead of DeprecationWarning. For example,
        re.compile("\d+\.\d+") now emits a SyntaxWarning ("\d" is an invalid escape
        sequence, use raw strings for regular expression: re.compile(r"\d+\.\d+")).
        In a future Python version, SyntaxError will eventually be raised, instead
        of SyntaxWarning.
    
    Command to reproduce the problem:
        find . -name "__pycache__" -print0 | xargs -0 rm -rf && python3.12 -B -m compileall -q .
    
    Here the removal of __pycache__ is just a hackish way of forcing a bytecode
    regeneration.
    
    --HG--
    branch : stable
    84ca27b0f478