Skip to content

Commit 4ded2eb

Browse files
authored
Fix/ignore flake8 errors in store related code (#1971)
This patch adds ignores for flake8 errors in store related code, it also removes one unused import in `rdflib/plugins/stores/sparqlconnector.py`. Mainly doing this in preparation for adding typing to `rdflib/store.py` which will invalidate large parts of the flakeheaven baseline there.
1 parent 9df5b21 commit 4ded2eb

File tree

8 files changed

+66
-45
lines changed

8 files changed

+66
-45
lines changed

rdflib/plugins/stores/auditable.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from rdflib import ConjunctiveGraph, Graph
2121
from rdflib.store import Store
2222

23-
destructiveOpLocks = {
23+
destructiveOpLocks = { # noqa: N816
2424
"add": None,
2525
"remove": None,
2626
}
@@ -59,7 +59,7 @@ def add(self, triple, context, quoted=False):
5959
if context is not None
6060
else None
6161
)
62-
ctxId = context.identifier if context is not None else None
62+
ctxId = context.identifier if context is not None else None # noqa: N806
6363
if list(self.store.triples(triple, context)):
6464
return # triple already in store, do nothing
6565
self.reverseOps.append((s, p, o, ctxId, "remove"))
@@ -81,7 +81,7 @@ def remove(self, spo, context=None):
8181
if context is not None
8282
else None
8383
)
84-
ctxId = context.identifier if context is not None else None
84+
ctxId = context.identifier if context is not None else None # noqa: N806
8585
if None in [subject, predicate, object_, context]:
8686
if ctxId:
8787
for s, p, o in context.triples((subject, predicate, object_)):

rdflib/plugins/stores/berkeleydb.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def __get_identifier(self):
7979

8080
identifier = property(__get_identifier)
8181

82-
def _init_db_environment(self, homeDir, create=True):
82+
def _init_db_environment(self, homeDir, create=True): # noqa: N803
8383
if not exists(homeDir):
8484
if create is True:
8585
mkdir(homeDir)
@@ -100,7 +100,7 @@ def is_open(self):
100100
def open(self, path, create=True):
101101
if not has_bsddb:
102102
return NO_STORE
103-
homeDir = path
103+
homeDir = path # noqa: N806
104104

105105
if self.__identifier is None:
106106
self.__identifier = URIRef(pathname2url(abspath(homeDir)))

rdflib/plugins/stores/concurrent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def __end_read(self):
8585
(s, p, o) = pending_removes.pop()
8686
try:
8787
self.store.remove((s, p, o))
88-
except:
88+
except: # noqa: E722
8989
# TODO: change to try finally?
9090
print(s, p, o, "Not in store to remove")
9191
pending_adds = self.__pending_adds

rdflib/plugins/stores/memory.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -46,33 +46,33 @@ def add(self, triple, context, quoted=False):
4646
spo = self.__spo
4747
try:
4848
po = spo[subject]
49-
except:
49+
except: # noqa: E722
5050
po = spo[subject] = {}
5151
try:
5252
o = po[predicate]
53-
except:
53+
except: # noqa: E722
5454
o = po[predicate] = {}
5555
o[object] = 1
5656

5757
pos = self.__pos
5858
try:
5959
os = pos[predicate]
60-
except:
60+
except: # noqa: E722
6161
os = pos[predicate] = {}
6262
try:
6363
s = os[object]
64-
except:
64+
except: # noqa: E722
6565
s = os[object] = {}
6666
s[subject] = 1
6767

6868
osp = self.__osp
6969
try:
7070
sp = osp[object]
71-
except:
71+
except: # noqa: E722
7272
sp = osp[object] = {}
7373
try:
7474
p = sp[subject]
75-
except:
75+
except: # noqa: E722
7676
p = sp[subject] = {}
7777
p[predicate] = 1
7878

@@ -88,7 +88,7 @@ def triples(self, triple_pattern, context=None):
8888
if subject != ANY: # subject is given
8989
spo = self.__spo
9090
if subject in spo:
91-
subjectDictionary = spo[subject]
91+
subjectDictionary = spo[subject] # noqa: N806
9292
if predicate != ANY: # subject+predicate is given
9393
if predicate in subjectDictionary:
9494
if object != ANY: # subject+predicate+object is given
@@ -116,7 +116,7 @@ def triples(self, triple_pattern, context=None):
116116
elif predicate != ANY: # predicate is given, subject unbound
117117
pos = self.__pos
118118
if predicate in pos:
119-
predicateDictionary = pos[predicate]
119+
predicateDictionary = pos[predicate] # noqa: N806
120120
if object != ANY: # predicate+object is given, subject unbound
121121
if object in predicateDictionary:
122122
for s in predicateDictionary[object].keys():
@@ -130,14 +130,14 @@ def triples(self, triple_pattern, context=None):
130130
elif object != ANY: # object is given, subject+predicate unbound
131131
osp = self.__osp
132132
if object in osp:
133-
objectDictionary = osp[object]
133+
objectDictionary = osp[object] # noqa: N806
134134
for s in objectDictionary.keys():
135135
for p in objectDictionary[s].keys():
136136
yield (s, p, object), self.__contexts()
137137
else: # subject+predicate+object unbound
138138
spo = self.__spo
139139
for s in spo.keys():
140-
subjectDictionary = spo[s]
140+
subjectDictionary = spo[s] # noqa: N806
141141
for p in subjectDictionary.keys():
142142
for o in subjectDictionary[p].keys():
143143
yield (s, p, o), self.__contexts()
@@ -184,12 +184,12 @@ def namespaces(self):
184184
def __contexts(self):
185185
return (c for c in []) # TODO: best way to return empty generator
186186

187-
def query(self, query, initNs, initBindings, queryGraph, **kwargs):
187+
def query(self, query, initNs, initBindings, queryGraph, **kwargs): # noqa: N803
188188
super(SimpleMemory, self).query(
189189
query, initNs, initBindings, queryGraph, **kwargs
190190
)
191191

192-
def update(self, update, initNs, initBindings, queryGraph, **kwargs):
192+
def update(self, update, initNs, initBindings, queryGraph, **kwargs): # noqa: N803
193193
super(SimpleMemory, self).update(
194194
update, initNs, initBindings, queryGraph, **kwargs
195195
)
@@ -347,7 +347,7 @@ def triples(self, triple_pattern, context=None):
347347
elif subject is not None: # subject is given
348348
spo = self.__spo
349349
if subject in spo:
350-
subjectDictionary = spo[subject]
350+
subjectDictionary = spo[subject] # noqa: N806
351351
if predicate is not None: # subject+predicate is given
352352
if predicate in subjectDictionary:
353353
if object_ is not None: # subject+predicate+object is given
@@ -383,7 +383,7 @@ def triples(self, triple_pattern, context=None):
383383
elif predicate is not None: # predicate is given, subject unbound
384384
pos = self.__pos
385385
if predicate in pos:
386-
predicateDictionary = pos[predicate]
386+
predicateDictionary = pos[predicate] # noqa: N806
387387
if object_ is not None: # predicate+object is given, subject unbound
388388
if object_ in predicateDictionary:
389389
for s in list(predicateDictionary[object_].keys()):
@@ -401,7 +401,7 @@ def triples(self, triple_pattern, context=None):
401401
elif object_ is not None: # object is given, subject+predicate unbound
402402
osp = self.__osp
403403
if object_ in osp:
404-
objectDictionary = osp[object_]
404+
objectDictionary = osp[object_] # noqa: N806
405405
for s in list(objectDictionary.keys()):
406406
for p in list(objectDictionary[s].keys()):
407407
triple = (s, p, object_)
@@ -411,7 +411,7 @@ def triples(self, triple_pattern, context=None):
411411
# Shouldn't get here if all other cases above worked correctly.
412412
spo = self.__spo
413413
for s in list(spo.keys()):
414-
subjectDictionary = spo[s]
414+
subjectDictionary = spo[s] # noqa: N806
415415
for p in list(subjectDictionary.keys()):
416416
for o in list(subjectDictionary[p].keys()):
417417
triple = (s, p, o)
@@ -530,7 +530,7 @@ def __add_triple_context(self, triple, triple_exists, context, quoted):
530530
if triple_context == self.__defaultContexts:
531531
del self.__tripleContexts[triple]
532532

533-
def __get_context_for_triple(self, triple, skipQuoted=False):
533+
def __get_context_for_triple(self, triple, skipQuoted=False): # noqa: N803
534534
"""return a list of contexts (str) for the triple, skipping
535535
quoted contexts if skipQuoted==True"""
536536

@@ -582,8 +582,8 @@ def __contexts(self, triple):
582582
if ctx_str is not None
583583
)
584584

585-
def query(self, query, initNs, initBindings, queryGraph, **kwargs):
585+
def query(self, query, initNs, initBindings, queryGraph, **kwargs): # noqa: N803
586586
super(Memory, self).query(query, initNs, initBindings, queryGraph, **kwargs)
587587

588-
def update(self, update, initNs, initBindings, queryGraph, **kwargs):
588+
def update(self, update, initNs, initBindings, queryGraph, **kwargs): # noqa: N803
589589
super(Memory, self).update(update, initNs, initBindings, queryGraph, **kwargs)

rdflib/plugins/stores/regexmatching.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def __reduce__(self):
3333
return (REGEXTerm, (str(""),))
3434

3535

36-
def regexCompareQuad(quad, regexQuad):
36+
def regexCompareQuad(quad, regexQuad): # noqa: N802, N803
3737
for index in range(4):
3838
if isinstance(regexQuad[index], REGEXTerm) and not regexQuad[
3939
index
@@ -83,7 +83,7 @@ def remove(self, triple, context=None):
8383
or None
8484
)
8585

86-
removeQuadList = []
86+
removeQuadList = [] # noqa: N806
8787
for (s1, p1, o1), cg in self.storage.triples((s, p, o), c):
8888
for ctx in cg:
8989
ctx = ctx.identifier
@@ -121,7 +121,7 @@ def triples(self, triple, context=None):
121121
or None
122122
)
123123
for (s1, p1, o1), cg in self.storage.triples((s, p, o), c):
124-
matchingCtxs = []
124+
matchingCtxs = [] # noqa: N806
125125
for ctx in cg:
126126
if c is None:
127127
if context is None or context.identifier.compiledExpr.match(

rdflib/plugins/stores/sparqlconnector.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import logging
33
from io import BytesIO
44
from typing import TYPE_CHECKING, Optional, Tuple
5-
from urllib.error import HTTPError, URLError
5+
from urllib.error import HTTPError
66
from urllib.parse import urlencode
77
from urllib.request import Request, urlopen
88

@@ -15,7 +15,7 @@
1515
import typing_extensions as te
1616

1717

18-
class SPARQLConnectorException(Exception):
18+
class SPARQLConnectorException(Exception): # noqa: N818
1919
pass
2020

2121

@@ -38,7 +38,7 @@ def __init__(
3838
self,
3939
query_endpoint: Optional[str] = None,
4040
update_endpoint: Optional[str] = None,
41-
returnFormat: str = "xml",
41+
returnFormat: str = "xml", # noqa: N803
4242
method: "te.Literal['GET', 'POST', 'POST_FORM']" = "GET",
4343
auth: Optional[Tuple[str, str]] = None,
4444
**kwargs,
@@ -105,7 +105,7 @@ def query(self, query, default_graph: str = None, named_graph: str = None):
105105
res = urlopen(
106106
Request(self.query_endpoint + qsa, headers=args["headers"])
107107
)
108-
except Exception as e:
108+
except Exception as e: # noqa: F841
109109
raise ValueError(
110110
"You did something wrong formulating either the URI or your SPARQL query"
111111
)
@@ -171,7 +171,7 @@ def update(
171171
args["headers"].update(headers)
172172

173173
qsa = "?" + urlencode(args["params"])
174-
res = urlopen(
174+
res = urlopen( # noqa: F841
175175
Request(
176176
self.update_endpoint + qsa, data=query.encode(), headers=args["headers"]
177177
)

rdflib/plugins/stores/sparqlstore.py

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def __init__(
9999
sparql11: bool = True,
100100
context_aware: bool = True,
101101
node_to_sparql: NodeToSparql = _node_to_sparql,
102-
returnFormat: str = "xml",
102+
returnFormat: str = "xml", # noqa: N803
103103
auth: Optional[Tuple[str, str]] = None,
104104
**sparqlconnector_kwargs,
105105
):
@@ -147,13 +147,20 @@ def rollback(self):
147147
def add(self, _, context=None, quoted=False):
148148
raise TypeError("The SPARQL store is read only")
149149

150-
def addN(self, quads):
150+
def addN(self, quads): # noqa: N802
151151
raise TypeError("The SPARQL store is read only")
152152

153153
def remove(self, _, context):
154154
raise TypeError("The SPARQL store is read only")
155155

156-
def update(self, query, initNs={}, initBindings={}, queryGraph=None, DEBUG=False):
156+
def update(
157+
self,
158+
query,
159+
initNs={}, # noqa: N803
160+
initBindings={},
161+
queryGraph=None,
162+
DEBUG=False,
163+
):
157164
raise TypeError("The SPARQL store is read only")
158165

159166
def _query(self, *args, **kwargs):
@@ -174,7 +181,12 @@ def _inject_prefixes(self, query, extra_bindings):
174181
)
175182

176183
def query(
177-
self, query, initNs=None, initBindings=None, queryGraph=None, DEBUG=False
184+
self,
185+
query,
186+
initNs=None, # noqa: N803
187+
initBindings=None,
188+
queryGraph=None,
189+
DEBUG=False,
178190
):
179191
self.debug = DEBUG
180192
assert isinstance(query, str)
@@ -509,7 +521,7 @@ def __init__(
509521
update_endpoint: Optional[str] = None,
510522
sparql11: bool = True,
511523
context_aware: bool = True,
512-
postAsEncoded: bool = True,
524+
postAsEncoded: bool = True, # noqa: N803
513525
autocommit: bool = True,
514526
dirty_reads: bool = False,
515527
**kwds,
@@ -576,7 +588,7 @@ def __len__(self, *args, **kwargs):
576588
return SPARQLStore.__len__(self, *args, **kwargs)
577589

578590
# TODO: FIXME: open is defined twice
579-
def open(self, configuration, create=False): # type: ignore[no-redef]
591+
def open(self, configuration, create=False): # type: ignore[no-redef] # noqa: F811
580592
"""
581593
sets the endpoint URLs for this SPARQLStore
582594
@@ -634,7 +646,7 @@ def add(self, spo, context=None, quoted=False):
634646
if self.autocommit:
635647
self.commit()
636648

637-
def addN(self, quads):
649+
def addN(self, quads): # noqa: N802
638650
"""Add a list of quads to the store."""
639651
if not self.update_endpoint:
640652
raise Exception("UpdateEndpoint is not set - call 'open'")
@@ -684,7 +696,7 @@ def remove(self, spo, context):
684696
if self.autocommit:
685697
self.commit()
686698

687-
def setTimeout(self, timeout):
699+
def setTimeout(self, timeout): # noqa: N802
688700
self._timeout = int(timeout)
689701

690702
def _update(self, update):
@@ -693,7 +705,14 @@ def _update(self, update):
693705

694706
SPARQLConnector.update(self, update)
695707

696-
def update(self, query, initNs={}, initBindings={}, queryGraph=None, DEBUG=False):
708+
def update(
709+
self,
710+
query,
711+
initNs={}, # noqa: N803
712+
initBindings={},
713+
queryGraph=None,
714+
DEBUG=False,
715+
):
697716
"""
698717
Perform a SPARQL Update Query against the endpoint,
699718
INSERT, LOAD, DELETE etc.

rdflib/store.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,9 @@ def add(
220220
"""
221221
self.dispatcher.dispatch(TripleAddedEvent(triple=triple, context=context))
222222

223-
def addN(self, quads: Iterable[Tuple["Node", "Node", "Node", "Graph"]]):
223+
def addN( # noqa: N802
224+
self, quads: Iterable[Tuple["Node", "Node", "Node", "Graph"]]
225+
):
224226
"""
225227
Adds each item in the list of statements to a specific context. The
226228
quoted argument is interpreted by formula-aware stores to indicate this
@@ -329,7 +331,7 @@ def contexts(self, triple=None):
329331
:returns: a generator over Nodes
330332
"""
331333

332-
def query(self, query, initNs, initBindings, queryGraph, **kwargs):
334+
def query(self, query, initNs, initBindings, queryGraph, **kwargs): # noqa: N803
333335
"""
334336
If stores provide their own SPARQL implementation, override this.
335337
@@ -345,7 +347,7 @@ def query(self, query, initNs, initBindings, queryGraph, **kwargs):
345347

346348
raise NotImplementedError
347349

348-
def update(self, update, initNs, initBindings, queryGraph, **kwargs):
350+
def update(self, update, initNs, initBindings, queryGraph, **kwargs): # noqa: N803
349351
"""
350352
If stores provide their own (SPARQL) Update implementation,
351353
override this.

0 commit comments

Comments
 (0)