Skip to content

Commit 14bb386

Browse files
authored
chore: remove pre python 3.5 regex related workaround (#2042)
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.
1 parent a2f96bc commit 14bb386

File tree

2 files changed

+17
-28
lines changed

2 files changed

+17
-28
lines changed

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,22 @@ and will be removed for release.
9090
<!-- -->
9191
<!-- -->
9292

93+
- Removed a pre python 3.5 regex related workaround in the REPLACE SPARQL
94+
function.
95+
[PR #2042](https://github.com/RDFLib/rdflib/pull/2042).
96+
97+
<!-- -->
98+
<!-- -->
99+
<!-- CHANGE BARRIER: END -->
100+
<!-- -->
101+
<!-- -->
102+
103+
<!-- -->
104+
<!-- -->
105+
<!-- CHANGE BARRIER: START -->
106+
<!-- -->
107+
<!-- -->
108+
93109
- PLACEHOLDER.
94110
Description of changes.
95111
Closed [issue #....](https://github.com/RDFLib/rdflib/issues/).

rdflib/plugins/sparql/operators.py

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import operator as pyop # python operators
1313
import random
1414
import re
15-
import sys
1615
import uuid
1716
import warnings
1817
from decimal import ROUND_HALF_UP, Decimal, InvalidOperation
@@ -227,28 +226,6 @@ def Builtin_REPLACE(expr, ctx):
227226
# python uses \1, xpath/sparql uses $1
228227
replacement = re.sub("\\$([0-9]*)", r"\\\1", replacement)
229228

230-
def _r(m):
231-
232-
# Now this is ugly.
233-
# Python has a "feature" where unmatched groups return None
234-
# then re.sub chokes on this.
235-
# see http://bugs.python.org/issue1519638 , fixed and errs in py3.5
236-
237-
# this works around and hooks into the internal of the re module...
238-
239-
# the match object is replaced with a wrapper that
240-
# returns "" instead of None for unmatched groups
241-
242-
class _m:
243-
def __init__(self, m):
244-
self.m = m
245-
self.string = m.string
246-
247-
def group(self, n):
248-
return m.group(n) or ""
249-
250-
return re._expand(pattern, _m(m), replacement)
251-
252229
cFlag = 0
253230
if flags:
254231
# Maps XPath REGEX flags (http://www.w3.org/TR/xpath-functions/#flags)
@@ -258,12 +235,8 @@ def group(self, n):
258235

259236
# @@FIXME@@ either datatype OR lang, NOT both
260237

261-
# this is necessary due to different treatment of unmatched groups in
262-
# python versions. see comments above in _r(m).
263-
compat_r = str(replacement) if sys.version_info[:2] >= (3, 5) else _r
264-
265238
return Literal(
266-
re.sub(str(pattern), compat_r, text, cFlag),
239+
re.sub(str(pattern), replacement, text, cFlag),
267240
datatype=text.datatype,
268241
lang=text.language,
269242
)

0 commit comments

Comments
 (0)