From fd9a3dac00ce20773b0e9a76efc63ccc0b6fd1ca Mon Sep 17 00:00:00 2001 From: Iwan Aucamp Date: Wed, 20 Jul 2022 01:20:33 +0200 Subject: [PATCH] chore: remove pre python 3.5 regex related workaround Removing a pre-python 3.5 regex related workaround as it uses a private method from the `re` module, and mypy complains about this, it is also no longer needed as we no longer support pre 3.5 versions of python. No tests are added as all changed parts of the `Builtin_REPLACE` function is already covered by existing tests. --- CHANGELOG.md | 16 ++++++++++++++++ rdflib/plugins/sparql/operators.py | 29 +---------------------------- 2 files changed, 17 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e7a87d9f3..1becba387 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -90,6 +90,22 @@ and will be removed for release. +- Removed a pre python 3.5 regex related workaround in the REPLACE SPARQL + function. + [PR #2042](https://github.com/RDFLib/rdflib/pull/2042). + + + + + + + + + + + + + - PLACEHOLDER. Description of changes. Closed [issue #....](https://github.com/RDFLib/rdflib/issues/). diff --git a/rdflib/plugins/sparql/operators.py b/rdflib/plugins/sparql/operators.py index 0f7b53255..c176691cb 100644 --- a/rdflib/plugins/sparql/operators.py +++ b/rdflib/plugins/sparql/operators.py @@ -12,7 +12,6 @@ import operator as pyop # python operators import random import re -import sys import uuid import warnings from decimal import ROUND_HALF_UP, Decimal, InvalidOperation @@ -227,28 +226,6 @@ def Builtin_REPLACE(expr, ctx): # python uses \1, xpath/sparql uses $1 replacement = re.sub("\\$([0-9]*)", r"\\\1", replacement) - def _r(m): - - # Now this is ugly. - # Python has a "feature" where unmatched groups return None - # then re.sub chokes on this. - # see http://bugs.python.org/issue1519638 , fixed and errs in py3.5 - - # this works around and hooks into the internal of the re module... - - # the match object is replaced with a wrapper that - # returns "" instead of None for unmatched groups - - class _m: - def __init__(self, m): - self.m = m - self.string = m.string - - def group(self, n): - return m.group(n) or "" - - return re._expand(pattern, _m(m), replacement) - cFlag = 0 if flags: # Maps XPath REGEX flags (http://www.w3.org/TR/xpath-functions/#flags) @@ -258,12 +235,8 @@ def group(self, n): # @@FIXME@@ either datatype OR lang, NOT both - # this is necessary due to different treatment of unmatched groups in - # python versions. see comments above in _r(m). - compat_r = str(replacement) if sys.version_info[:2] >= (3, 5) else _r - return Literal( - re.sub(str(pattern), compat_r, text, cFlag), + re.sub(str(pattern), replacement, text, cFlag), datatype=text.datatype, lang=text.language, )