contrib: use a raw string for a regular expression literal that contains backslashes in signet/miner #28883

pull muxator wants to merge 1 commits into bitcoin:master from bancaditalia:miner-use-raw-strings changing 1 files +1 −1
  1. muxator commented at 3:52 pm on November 15, 2023: none

    Running contrib/signet/miner under python >= 3.12 causes a SyntaxWarning. The problem was already present in previous versions, but it only triggered a DeprecationWarning, which was not 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 (see the reference given later).

    Command to see the warning at runtime under python3.11 (DeprecationWarning, needs “-Walways”):

    0$ python3.11 -Walways ./contrib/signet/miner
    1<BASE>/contrib/signet/miner:33: DeprecationWarning: invalid escape sequence '\d'
    2  RE_MULTIMINER = re.compile("^(\d+)(-(\d+))?/(\d+)$")
    32023-11-15 16:02:49 ERROR Must specify command
    

    Command to see the warning at runtime under python3.12 (SyntaxWarning, no modifiers needed):

    0$ python3.12 ./contrib/signet/miner
    1<BASE>/contrib/signet/miner:33: SyntaxWarning: invalid escape sequence '\d'
    2  RE_MULTIMINER = re.compile("^(\d+)(-(\d+))?/(\d+)$")
    32023-11-15 16:03:00 ERROR Must specify command
    

    Reference (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;

  2. contrib: use a raw string for a regular expression literal that contains backslashes in signet/miner
    Running the miner under python >= 3.12 causes a SyntaxWarning. The problem was
    already present in previous versions, but it only triggered a
    DeprecationWarning, which was not 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 (see the reference given
    later).
    
    Command to see the warning at runtime under python3.11 (DeprecationWarning,
    needs "-Walways"):
        $ python3.11 -Walways ./contrib/signet/miner
        <BASE>/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
        <BASE>/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
    
    Reference ( 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;
    defdf67765
  3. DrahtBot commented at 3:52 pm on November 15, 2023: contributor

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Code Coverage

    For detailed information about the code coverage, see the test coverage report.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK maflcko, ajtowns

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

  4. DrahtBot added the label Scripts and tools on Nov 15, 2023
  5. maflcko commented at 3:59 pm on November 15, 2023: member
    lgtm ACK defdf67765a3d757f4d3840602eef7ccdac9bb49
  6. fanquake requested review from ajtowns on Nov 15, 2023
  7. ajtowns commented at 2:52 am on November 16, 2023: contributor
    utACK defdf67765a3d757f4d3840602eef7ccdac9bb49
  8. DrahtBot removed review request from ajtowns on Nov 16, 2023
  9. fanquake merged this on Nov 16, 2023
  10. fanquake closed this on Nov 16, 2023

  11. muxator deleted the branch on Nov 21, 2023
  12. bitcoin locked this on Nov 20, 2024

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-12-21 15:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me