From 30366fde845bbc50a99a9a692b5676808750373f Mon Sep 17 00:00:00 2001 From: muxator Date: Wed, 15 Nov 2023 15:55:20 +0100 Subject: [PATCH] contrib: use a raw string for a regular expression literal that contains backslashes in signet/miner MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Running the miner under python < 3.11 triggered a DeprecationWarning (hidden by default on those versions). Running under python >= 3.12 it generates a SyntaxWarning, which is shown by default. The change is useful for future-proofing the code base, since future python versions will start to exit with a runtime exception. Command to see the warning at runtime under python3.11 (DeprecationWarning, needs "-Walways"): $ python3.11 -Walways ./contrib/signet/miner /contrib/signet/miner:33: DeprecationWarning: invalid escape sequence '\d' RE_MULTIMINER = re.compile("^(\d+)(-(\d+))?/(\d+)$") 2023-11-15 16:02:49 ERROR Must specify command Command to see the warning at runtime under python3.12 (SyntaxWarning, no modifiers needed): $ python3.12 ./contrib/signet/miner /contrib/signet/miner:33: SyntaxWarning: invalid escape sequence '\d' RE_MULTIMINER = re.compile("^(\d+)(-(\d+))?/(\d+)$") 2023-11-15 16:03:00 ERROR Must specify command References: From https://docs.python.org/3.8/library/re.html : Regular expressions use the backslash character ('\') [...]. This collides with Python’s usage of the same character for the same purpose in string literals; [...] Also, please note that any invalid escape sequences in Python’s usage of the backslash in string literals now generate a DeprecationWarning and in the future this will become a SyntaxError. The solution is to use Python’s raw string notation for regular expression patterns; --- contrib/signet/miner | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/signet/miner b/contrib/signet/miner index 61d9f62be71844..e5daf9f993eaa3 100755 --- a/contrib/signet/miner +++ b/contrib/signet/miner @@ -30,7 +30,7 @@ logging.basicConfig( SIGNET_HEADER = b"\xec\xc7\xda\xa2" PSBT_SIGNET_BLOCK = b"\xfc\x06signetb" # proprietary PSBT global field holding the block being signed -RE_MULTIMINER = re.compile("^(\d+)(-(\d+))?/(\d+)$") +RE_MULTIMINER = re.compile(r"^(\d+)(-(\d+))?/(\d+)$") def create_coinbase(height, value, spk): cb = CTransaction()