Skip to content

Commit ba855c2

Browse files
pre-commit-ci[bot]aucampia
authored andcommitted
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 2d6a05d commit ba855c2

21 files changed

+121
-121
lines changed

rdflib/namespace/__init__.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ def __getattr__(cls, name: str):
238238
return cls.__getitem__(name)
239239

240240
def __repr__(cls) -> str:
241-
return f'Namespace({str(cls._NS)!r})'
241+
return f"Namespace({str(cls._NS)!r})"
242242

243243
def __str__(cls) -> str:
244244
return str(cls._NS)
@@ -275,9 +275,9 @@ def as_jsonld_context(self, pfx: str) -> dict:
275275
terms = {pfx: str(self._NS)}
276276
for key, term in self.__annotations__.items():
277277
if issubclass(term, URIRef):
278-
terms[key] = f'{pfx}:{key}'
278+
terms[key] = f"{pfx}:{key}"
279279

280-
return {'@context': terms}
280+
return {"@context": terms}
281281

282282

283283
class DefinedNamespace(metaclass=DefinedNamespaceMeta):

rdflib/parser.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -197,14 +197,14 @@ class URLInputSource(InputSource):
197197
links: List[str]
198198

199199
@classmethod
200-
def getallmatchingheaders(cls, message: 'HTTPMessage', name):
200+
def getallmatchingheaders(cls, message: "HTTPMessage", name):
201201
# This is reimplemented here, because the method
202202
# getallmatchingheaders from HTTPMessage is broken since Python 3.0
203203
name = name.lower()
204204
return [val for key, val in message.items() if key.lower() == name]
205205

206206
@classmethod
207-
def get_links(cls, response: 'HTTPResponse'):
207+
def get_links(cls, response: "HTTPResponse"):
208208
linkslines = cls.getallmatchingheaders(response.headers, "Link")
209209
retarray = []
210210
for linksline in linkslines:
@@ -214,8 +214,8 @@ def get_links(cls, response: 'HTTPResponse'):
214214
return retarray
215215

216216
def get_alternates(self, type_: Optional[str] = None) -> List[str]:
217-
typestr: Optional[str] = f"type=\"{type_}\"" if type_ else None
218-
relstr = "rel=\"alternate\""
217+
typestr: Optional[str] = f'type="{type_}"' if type_ else None
218+
relstr = 'rel="alternate"'
219219
alts = []
220220
for link in self.links:
221221
parts = [p.strip() for p in link.split(";")]

rdflib/plugins/sparql/algebra.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,7 @@ def sparql_query_text(node):
964964
)
965965
aggr_vars[agg_func.res].append(agg_func.vars)
966966

967-
agg_func_name = agg_func.name.split('_')[1]
967+
agg_func_name = agg_func.name.split("_")[1]
968968
distinct = ""
969969
if agg_func.distinct:
970970
distinct = agg_func.distinct + " "

rdflib/util.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,9 @@ def from_n3(s: str, default=None, backend=None, nsm=None):
194194
return Literal(s == "true")
195195
elif (
196196
s.lower()
197-
.replace('.', '', 1)
198-
.replace('-', '', 1)
199-
.replace('e', '', 1)
197+
.replace(".", "", 1)
198+
.replace("-", "", 1)
199+
.replace("e", "", 1)
200200
.isnumeric()
201201
):
202202
if "e" in s.lower():

test/jsonld/runner.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ def make_fake_urlinputsource(input_uri, format=None, suite_base=None, options={}
4141
if "httpLink" in options:
4242
source.links.append(options["httpLink"])
4343
if "contentType" in options:
44-
source.content_type = options['contentType']
44+
source.content_type = options["contentType"]
4545
if "redirectTo" in options:
46-
redir = suite_base + options['redirectTo']
46+
redir = suite_base + options["redirectTo"]
4747
local_redirect = redir.replace(
4848
"https://w3c.github.io/json-ld-api/tests/", "./"
4949
)

test/test_graph/test_namespace_rebinding.py

+39-39
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def test_binding_replace():
3434
g.bind("foaf", FOAF1)
3535
g.bind("foaf2", FOAF2)
3636
assert len(list(g.namespaces())) == 2
37-
assert list(g.namespaces()) == [('foaf', foaf1_uri), ("foaf2", foaf2_uri)]
37+
assert list(g.namespaces()) == [("foaf", foaf1_uri), ("foaf2", foaf2_uri)]
3838

3939
# Now you want to "upgrade" to FOAF2=>foaf and try the obvious:
4040
g.bind("foaf", FOAF2)
@@ -61,7 +61,7 @@ def test_binding_replace():
6161

6262
assert list(g.namespaces()) == [
6363
("foaf", foaf2_uri), # Should be present but has been removed.
64-
('oldfoaf', foaf1_uri),
64+
("oldfoaf", foaf1_uri),
6565
]
6666

6767
# 2. Changing the prefix of an existing namespace=>prefix binding:
@@ -72,7 +72,7 @@ def test_binding_replace():
7272

7373
# Which, as things stand, results in:
7474

75-
assert list(g.namespaces()) == [("foaf", foaf2_uri), ('foaf1', foaf1_uri)]
75+
assert list(g.namespaces()) == [("foaf", foaf2_uri), ("foaf1", foaf1_uri)]
7676

7777
# In which the attempted change from `oldfoaf` to (the already
7878
# bound-to-a different-namespace `foaf`) was intercepted and
@@ -82,13 +82,13 @@ def test_binding_replace():
8282
g.bind("oldfoaf", FOAF1, replace=True)
8383

8484
# The bindings are again as desired
85-
assert list(g.namespaces()) == [("foaf", foaf2_uri), ('oldfoaf', foaf1_uri)]
85+
assert list(g.namespaces()) == [("foaf", foaf2_uri), ("oldfoaf", foaf1_uri)]
8686

8787
# Next time through, set override to False
8888
g.bind("foaf", FOAF1, override=False)
8989

9090
# And the bindings will remain as desired
91-
assert list(g.namespaces()) == [("foaf", foaf2_uri), ('oldfoaf', foaf1_uri)]
91+
assert list(g.namespaces()) == [("foaf", foaf2_uri), ("oldfoaf", foaf1_uri)]
9292

9393
# 3. Parsing data with prefix=>namespace bindings
9494
# Let's see the situation regarding namespace bindings
@@ -108,7 +108,7 @@ def test_binding_replace():
108108
# non-clashing prefix of `foaf1` is rebound to FOAF1 in
109109
# place of the existing `oldfoaf` prefix
110110

111-
assert list(g.namespaces()) == [("foaf", foaf2_uri), ('foaf1', foaf1_uri)]
111+
assert list(g.namespaces()) == [("foaf", foaf2_uri), ("foaf1", foaf1_uri)]
112112

113113
# Yes, namespace bindings in parsed data replace existing
114114
# bindings (i.e. `oldfoaf` was replaced by `foaf1`), just
@@ -128,7 +128,7 @@ def test_binding_replace():
128128
# by the `foaf2=>FOAF2` binding specified in the N3 source
129129

130130
assert list(g.namespaces()) == [
131-
('foaf1', foaf1_uri),
131+
("foaf1", foaf1_uri),
132132
("foaf2", foaf2_uri),
133133
]
134134

@@ -146,7 +146,7 @@ def test_binding_replace():
146146
# used
147147

148148
assert list(g.namespaces()) == [
149-
('foaf1', foaf1_uri),
149+
("foaf1", foaf1_uri),
150150
("foaf2", foaf2_uri),
151151
]
152152

@@ -161,7 +161,7 @@ def test_binding_replace():
161161

162162
assert list(g.namespaces()) == [
163163
("foaf2", foaf2_uri),
164-
('foaf', foaf1_uri),
164+
("foaf", foaf1_uri),
165165
]
166166

167167
# Prefixes are bound to namespaces which in turn have a URIRef
@@ -191,11 +191,11 @@ def test_prefix_alias_disallowed():
191191

192192
g = Graph(bind_namespaces="none")
193193
g.bind("owl", OWL)
194-
assert ('owl', URIRef('http://www.w3.org/2002/07/owl#')) in list(g.namespaces())
194+
assert ("owl", URIRef("http://www.w3.org/2002/07/owl#")) in list(g.namespaces())
195195

196196
g.bind("wol", OWL, override=False)
197-
assert ('owl', URIRef('http://www.w3.org/2002/07/owl#')) in list(g.namespaces())
198-
assert ('wol', URIRef('http://www.w3.org/2002/07/owl#')) not in list(g.namespaces())
197+
assert ("owl", URIRef("http://www.w3.org/2002/07/owl#")) in list(g.namespaces())
198+
assert ("wol", URIRef("http://www.w3.org/2002/07/owl#")) not in list(g.namespaces())
199199

200200

201201
def test_rebind_prefix_succeeds():
@@ -204,11 +204,11 @@ def test_rebind_prefix_succeeds():
204204

205205
g = Graph(bind_namespaces="none")
206206
g.bind("owl", OWL)
207-
assert ('owl', URIRef('http://www.w3.org/2002/07/owl#')) in list(g.namespaces())
207+
assert ("owl", URIRef("http://www.w3.org/2002/07/owl#")) in list(g.namespaces())
208208

209209
g.bind("wol", OWL)
210-
assert ('wol', URIRef('http://www.w3.org/2002/07/owl#')) in list(g.namespaces())
211-
assert ('owl', URIRef('http://www.w3.org/2002/07/owl#')) not in list(g.namespaces())
210+
assert ("wol", URIRef("http://www.w3.org/2002/07/owl#")) in list(g.namespaces())
211+
assert ("owl", URIRef("http://www.w3.org/2002/07/owl#")) not in list(g.namespaces())
212212

213213

214214
def test_parse_rebinds_prefix():
@@ -223,14 +223,14 @@ def test_parse_rebinds_prefix():
223223

224224
# Use full set of namespace bindings, including foaf
225225
g = Graph(bind_namespaces="none")
226-
g.bind('foaf', FOAF1)
227-
assert ('foaf', foaf1_uri) in list(g.namespaces())
226+
g.bind("foaf", FOAF1)
227+
assert ("foaf", foaf1_uri) in list(g.namespaces())
228228

229229
g.parse(data=data, format="n3")
230230

231231
# foaf no longer in set of namespace bindings
232-
assert ('foaf', foaf1_uri) not in list(g.namespaces())
233-
assert ('friend-of-a-friend', foaf1_uri) in list(g.namespaces())
232+
assert ("foaf", foaf1_uri) not in list(g.namespaces())
233+
assert ("friend-of-a-friend", foaf1_uri) in list(g.namespaces())
234234

235235

236236
@pytest.mark.xfail(
@@ -254,7 +254,7 @@ def test_automatic_handling_of_unknown_predicates():
254254

255255
g = Graph(bind_namespaces="none")
256256

257-
g.add((tarek, URIRef('http://xmlns.com/foaf/0.1/name'), Literal("Tarek")))
257+
g.add((tarek, URIRef("http://xmlns.com/foaf/0.1/name"), Literal("Tarek")))
258258

259259
assert len(list(g.namespaces())) > 0
260260

@@ -263,7 +263,7 @@ def test_automatic_handling_of_unknown_predicates_only_effected_after_serializat
263263

264264
g = Graph(bind_namespaces="none")
265265

266-
g.add((tarek, URIRef('http://xmlns.com/foaf/0.1/name'), Literal("Tarek")))
266+
g.add((tarek, URIRef("http://xmlns.com/foaf/0.1/name"), Literal("Tarek")))
267267

268268
assert "@prefix ns1: <http://xmlns.com/foaf/0.1/> ." in g.serialize(format="n3")
269269

@@ -282,27 +282,27 @@ def test_multigraph_bindings():
282282

283283
g1 = Graph(store, identifier=context1, bind_namespaces="none")
284284

285-
g1.bind('foaf', FOAF1)
286-
assert list(g1.namespaces()) == [('foaf', foaf1_uri)]
287-
assert list(store.namespaces()) == [('foaf', foaf1_uri)]
285+
g1.bind("foaf", FOAF1)
286+
assert list(g1.namespaces()) == [("foaf", foaf1_uri)]
287+
assert list(store.namespaces()) == [("foaf", foaf1_uri)]
288288

289289
g1.add((tarek, FOAF1.name, Literal("tarek")))
290290

291-
assert list(store.namespaces()) == [('foaf', foaf1_uri)]
291+
assert list(store.namespaces()) == [("foaf", foaf1_uri)]
292292

293293
g2 = Graph(store, identifier=context2, bind_namespaces="none")
294294
g2.parse(data=data, format="n3")
295295

296296
# The parser-caused rebind is in the underlying store and all objects
297297
# that use the store see the changed binding:
298-
assert list(store.namespaces()) == [('friend-of-a-friend', foaf1_uri)]
299-
assert list(g1.namespaces()) == [('friend-of-a-friend', foaf1_uri)]
298+
assert list(store.namespaces()) == [("friend-of-a-friend", foaf1_uri)]
299+
assert list(g1.namespaces()) == [("friend-of-a-friend", foaf1_uri)]
300300

301301
# Including newly-created objects that use the store
302302
cg = ConjunctiveGraph(store=store)
303303

304-
assert ('foaf', foaf1_uri) not in list(cg.namespaces())
305-
assert ('friend-of-a-friend', foaf1_uri) in list(cg.namespaces())
304+
assert ("foaf", foaf1_uri) not in list(cg.namespaces())
305+
assert ("friend-of-a-friend", foaf1_uri) in list(cg.namespaces())
306306

307307
assert len(list(g1.namespaces())) == 6
308308
assert len(list(g2.namespaces())) == 6
@@ -324,24 +324,24 @@ def test_multigraph_bindings():
324324

325325
# Add foaf2 binding if not already bound
326326
cg.bind("foaf2", FOAF2, override=False)
327-
assert ('foaf2', foaf2_uri) in list(cg.namespaces())
327+
assert ("foaf2", foaf2_uri) in list(cg.namespaces())
328328

329329
# Impose foaf binding ... if not already bound
330330
cg.bind("foaf", FOAF1, override=False)
331-
assert ('foaf', foaf1_uri) not in list(cg.namespaces())
331+
assert ("foaf", foaf1_uri) not in list(cg.namespaces())
332332

333333

334334
def test_new_namespace_new_prefix():
335335
g = Graph(bind_namespaces="none")
336336
g.bind("foaf", FOAF1)
337-
assert list(g.namespaces()) == [('foaf', foaf1_uri)]
337+
assert list(g.namespaces()) == [("foaf", foaf1_uri)]
338338

339339

340340
def test_change_prefix_override_true():
341341
g = Graph(bind_namespaces="none")
342342

343343
g.bind("foaf", FOAF1)
344-
assert list(g.namespaces()) == [('foaf', foaf1_uri)]
344+
assert list(g.namespaces()) == [("foaf", foaf1_uri)]
345345

346346
g.bind("oldfoaf", FOAF1)
347347
# Changed
@@ -352,7 +352,7 @@ def test_change_prefix_override_false():
352352
g = Graph(bind_namespaces="none")
353353

354354
g.bind("foaf", FOAF1)
355-
assert list(g.namespaces()) == [('foaf', foaf1_uri)]
355+
assert list(g.namespaces()) == [("foaf", foaf1_uri)]
356356

357357
g.bind("oldfoaf", FOAF1, override=False)
358358
# No change
@@ -363,7 +363,7 @@ def test_change_namespace_override_true():
363363
g = Graph(bind_namespaces="none")
364364

365365
g.bind("foaf", FOAF1)
366-
assert list(g.namespaces()) == [('foaf', foaf1_uri)]
366+
assert list(g.namespaces()) == [("foaf", foaf1_uri)]
367367

368368
g.bind("foaf", FOAF2)
369369
# Different prefix used
@@ -374,7 +374,7 @@ def test_change_namespace_override_false():
374374
g = Graph(bind_namespaces="none")
375375

376376
g.bind("foaf", FOAF1)
377-
assert list(g.namespaces()) == [('foaf', foaf1_uri)]
377+
assert list(g.namespaces()) == [("foaf", foaf1_uri)]
378378

379379
# Different namespace so override is irrelevant in this case
380380
g.bind("foaf", FOAF2, override=False)
@@ -386,14 +386,14 @@ def test_new_namespace_override_false():
386386
g = Graph(bind_namespaces="none")
387387

388388
g.bind("foaf", FOAF2)
389-
assert list(g.namespaces()) == [('foaf', foaf2_uri)]
389+
assert list(g.namespaces()) == [("foaf", foaf2_uri)]
390390

391391
# Namespace not already bound so override is irrelevant in this case
392392
g.bind("owl", OWL, override=False)
393393
# Given prefix used
394394
assert list(g.namespaces()) == [
395395
("foaf", foaf2_uri),
396-
('owl', URIRef('http://www.w3.org/2002/07/owl#')),
396+
("owl", URIRef("http://www.w3.org/2002/07/owl#")),
397397
]
398398

399399

@@ -406,7 +406,7 @@ def test_change_namespace_and_prefix():
406406
g = Graph(bind_namespaces="none")
407407

408408
g.bind("foaf", FOAF1)
409-
assert list(g.namespaces()) == [('foaf', foaf1_uri)]
409+
assert list(g.namespaces()) == [("foaf", foaf1_uri)]
410410

411411
g.bind("foaf", FOAF2, replace=True)
412412
assert list(g.namespaces()) == [("foaf", foaf2_uri)]

test/test_issues/test_issue1404.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ def test_skolem_de_skolem_roundtrip():
88
Issue: https://github.com/RDFLib/rdflib/issues/1404
99
"""
1010

11-
ttl = '''
11+
ttl = """
1212
@prefix wd: <http://www.wikidata.org/entity/> .
1313
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
1414
1515
wd:Q1203 foaf:knows [ a foaf:Person;
1616
foaf:name "Ringo" ].
17-
'''
17+
"""
1818

1919
graph = Graph()
20-
graph.parse(data=ttl, format='turtle')
20+
graph.parse(data=ttl, format="turtle")
2121

2222
query = {
2323
"subject": URIRef("http://www.wikidata.org/entity/Q1203"),

test/test_issues/test_issue1808.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ def test():
1717
for s, p, o in gs:
1818
assert isinstance(s, URIRef) and s.__contains__(rdflib_skolem_genid)
1919

20-
query_with_iri = 'select ?p ?o {{ <{}> ?p ?o }}'.format(s)
21-
query_for_all = 'select ?s ?p ?o { ?s ?p ?o }'
20+
query_with_iri = "select ?p ?o {{ <{}> ?p ?o }}".format(s)
21+
query_for_all = "select ?s ?p ?o { ?s ?p ?o }"
2222

2323
count = 0
2424
for row in gs.query(query_with_iri):
@@ -31,7 +31,7 @@ def test():
3131
assert count == 1
3232

3333
gp = Graph()
34-
gp.parse(data=gs.serialize(format='turtle'), format='turtle')
34+
gp.parse(data=gs.serialize(format="turtle"), format="turtle")
3535

3636
count = 0
3737
for row in gp.query(query_with_iri):

0 commit comments

Comments
 (0)