From 9bcb21389adc62dd099afd0665990aa0128a7ad3 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Sun, 5 May 2024 19:02:41 +0200 Subject: [PATCH] Fix SyntaxWarning on Python 3.12 --- plugins/DDG/test.py | 4 ++-- plugins/Dict/local/dictclient.py | 2 +- plugins/Fediverse/utils.py | 10 +++++----- plugins/Math/local/convertcore.py | 8 ++++---- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/plugins/DDG/test.py b/plugins/DDG/test.py index c10ba9955..a3b96a407 100644 --- a/plugins/DDG/test.py +++ b/plugins/DDG/test.py @@ -39,7 +39,7 @@ class DDGTestCase(PluginTestCase): def testSearch(self): self.assertRegexp( - 'ddg search wikipedia', 'Wikipedia.*? - .*?https?\:\/\/') + r'ddg search wikipedia', 'Wikipedia.*? - .*?https?\:\/\/') self.assertRegexp( 'ddg search en.wikipedia.org', 'Wikipedia, the free encyclopedia\x02 - ' @@ -47,6 +47,6 @@ class DDGTestCase(PluginTestCase): with conf.supybot.plugins.DDG.region.context('fr-fr'): self.assertRegexp( 'ddg search wikipedia', - 'Wikipédia, l\'encyclopédie libre - .*?https?\:\/\/') + r'Wikipédia, l\'encyclopédie libre - .*?https?\:\/\/') # vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: diff --git a/plugins/Dict/local/dictclient.py b/plugins/Dict/local/dictclient.py index 04251250a..683e6e8e1 100644 --- a/plugins/Dict/local/dictclient.py +++ b/plugins/Dict/local/dictclient.py @@ -194,7 +194,7 @@ class Connection: if code != 151 or code is None: break - resultword, resultdb = re.search('^"(.+)" (\S+)', text).groups() + resultword, resultdb = re.search(r'^"(.+)" (\S+)', text).groups() defstr = self.get100block() retval.append(Definition(self, self.getdbobj(resultdb), resultword, defstr)) diff --git a/plugins/Fediverse/utils.py b/plugins/Fediverse/utils.py index c55b1c42a..fda125d40 100644 --- a/plugins/Fediverse/utils.py +++ b/plugins/Fediverse/utils.py @@ -33,11 +33,11 @@ import datetime # Credits for the regexp and function: https://stackoverflow.com/a/2765366/539465 _XSD_DURATION_RE = re.compile( - "(?P-?)P" - "(?:(?P\d+)Y)?" - "(?:(?P\d+)M)?" - "(?:(?P\d+)D)?" - "(?:T(?:(?P\d+)H)?(?:(?P\d+)M)?(?:(?P\d+)S)?)?" + r"(?P-?)P" + r"(?:(?P\d+)Y)?" + r"(?:(?P\d+)M)?" + r"(?:(?P\d+)D)?" + r"(?:T(?:(?P\d+)H)?(?:(?P\d+)M)?(?:(?P\d+)S)?)?" ) diff --git a/plugins/Math/local/convertcore.py b/plugins/Math/local/convertcore.py index 42948c791..53003a4fd 100644 --- a/plugins/Math/local/convertcore.py +++ b/plugins/Math/local/convertcore.py @@ -849,7 +849,7 @@ class UnitGroup: def updateCurrentUnit(self, text, cursorPos): "Set current unit number" - self.currentNum = len(re.findall('[\*/]', text[:cursorPos])) + self.currentNum = len(re.findall(r'[\*/]', text[:cursorPos])) def currentUnit(self): "Return current unit if its a full match, o/w None" @@ -925,7 +925,7 @@ class UnitGroup: def parseGroup(self, text): "Return list of units from text string" unitList = [] - parts = [part.strip() for part in re.split('([\*/])', text)] + parts = [part.strip() for part in re.split(r'([\*/])', text)] numerator = 1 while parts: unit = self.parseUnit(parts.pop(0)) @@ -1180,7 +1180,7 @@ class Unit: self.equiv = unitList[0].strip() if self.equiv[0] == '[': # used only for non-linear units try: - self.equiv, self.fromEqn = re.match('\[(.*?)\](.*)', \ + self.equiv, self.fromEqn = re.match(r'\[(.*?)\](.*)', \ self.equiv).groups() if ';' in self.fromEqn: self.fromEqn, self.toEqn = self.fromEqn.split(';', 1) @@ -1190,7 +1190,7 @@ class Unit: raise UnitDataError('Bad equation for "%s"' % self.name) else: # split factor and equiv unit for linear parts = self.equiv.split(None, 1) - if len(parts) > 1 and re.search('[^\d\.eE\+\-\*/]', parts[0]) \ + if len(parts) > 1 and re.search(r'[^\d\.eE\+\-\*/]', parts[0]) \ == None: # only allowed digits and operators try: self.factor = float(eval(parts[0]))