Skip to content

Commit

Permalink
Merge pull request SCons#4501 from mwichmann/maint/py313-re
Browse files Browse the repository at this point in the history
Fix a Python 3.13 problem in re.sub usage
  • Loading branch information
bdbaddog authored Mar 22, 2024
2 parents 9beb493 + 9c97705 commit 2f57d9d
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.
- Dump() with json format selected now recognizes additional compound types
(UserDict and UserList), which improves the detail of the display.
json output is also sorted, to match the default display.
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 2f57d9d

Please sign in to comment.