[Python] Python 3.12 SyntaxWarning: invalid escape sequence on triple-quoted string, `\d` must...

Discussão em 'Python' iniciado por Stack, Julho 3, 2025.

  1. Stack

    Stack Membro Participativo

    After updating to Python 3.12, I get warnings about invalid escape sequence on some triple-quotes comments.

    Is this a new restriction? I have the habit of documenting code using triple-quoted string, but this has never been a problem prior to Python 3.12.

    python3 --version
    Python 3.12.0
    $ ./some_script.py
    /some_script.py:123: SyntaxWarning: invalid escape sequence '\d'
    """


    I tried replacing all lines with \d:

    20230808122708.445|INFO|C:\dist\work\trk-fullstack-test\namespaces.py

    with \\d:

    20230808122708.445|INFO|C:\\dist\work\trk-fullstack-test\namespaces.py

    The warning disappears.

    Suppressing the warning do not seem to work:

    import warnings
    warnings.filterwarnings('ignore', category=SyntaxWarning)


    I hope I do not have to escape all Windows paths documented in triplequotes in our code.

    Continue reading...

Compartilhe esta Página