Skip to content

Commit

Permalink
Fix a Python 3.13 problem in re.sub usage
Browse files Browse the repository at this point in the history
re.sub's count and flags arguments are transitioning to keyword-only.
With 3.13a5, usage as positional args issues a DeprecationWarning,
which caused one SCons test to fail.  Updated in test framework
and in bin/update-release-info.py.

Signed-off-by: Mats Wichmann <mats@linux.com>
  • Loading branch information
mwichmann committed Mar 21, 2024
1 parent 04c86e1 commit 43c6529
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER
From Mats Wichmann:

- Updated Value Node docs and tests.
- Python 3.13 compat: re.sub deprecated count, flags as positional args,
caused update-release-info test to fail.


RELEASE 4.7.0 - Sun, 17 Mar 2024 17:22:20 -0700
Expand Down
6 changes: 3 additions & 3 deletions bin/update-release-info.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,19 +218,19 @@ def __init__(self, file, orig=None):

def sub(self, pattern, replacement, count=1):
""" XXX """
self.content = re.sub(pattern, replacement, self.content, count)
self.content = re.sub(pattern, replacement, self.content, count=count)

def replace_assign(self, name, replacement, count=1):
""" XXX """
self.sub('\n' + name + ' = .*', '\n' + name + ' = ' + replacement)

def replace_version(self, count=1):
""" XXX """
self.content = self.match_rel.sub(rel_info.version_string, self.content, count)
self.content = self.match_rel.sub(rel_info.version_string, self.content, count=count)

def replace_date(self, count=1):
""" XXX """
self.content = self.match_date.sub(rel_info.new_date, self.content, count)
self.content = self.match_date.sub(rel_info.new_date, self.content, count=count)

def __del__(self):
""" XXX """
Expand Down
4 changes: 2 additions & 2 deletions testing/framework/TestSCons.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,14 +668,14 @@ def normalize_ps(self, s):
return s

@staticmethod
def to_bytes_re_sub(pattern, repl, str, count: int=0, flags: int=0):
def to_bytes_re_sub(pattern, repl, string, count: int=0, flags: int=0):
"""
Wrapper around re.sub to change pattern and repl to bytes to work with
both python 2 & 3
"""
pattern = to_bytes(pattern)
repl = to_bytes(repl)
return re.sub(pattern, repl, str, count, flags)
return re.sub(pattern, repl, string, count=count, flags=flags)

def normalize_pdf(self, s):
s = self.to_bytes_re_sub(r'/(Creation|Mod)Date \(D:[^)]*\)',
Expand Down

0 comments on commit 43c6529

Please sign in to comment.