The solution is to use Python’s raw string notation for regular expression patterns; backslashes are not handled in any special way in a string literal prefixed with 'r'. So r"\n" is a two-character string containing '\' and 'n', while "\n" is a one-character string containing a newline. Usually patterns will be expressed in Python code using this raw string notation.
I've run the build four times: with Python 3.11 (with and without my patch) and Python 3.12 (with and without my patch). The output of preproc.py (proto.magicrc) is identical in all four runs, but with my patch Python 3.12 no longer produces warnings. And presumably in some future version of Python the warning will become an error.
When Python 3.12 is used to build magic, these warnings appear:
I've fixed it by using raw strings. See https://docs.python.org/3/library/re.html:
I've run the build four times: with Python 3.11 (with and without my patch) and Python 3.12 (with and without my patch). The output of preproc.py (proto.magicrc) is identical in all four runs, but with my patch Python 3.12 no longer produces warnings. And presumably in some future version of Python the warning will become an error.