Skip to content

Commit 8bbb30d

Browse files
Reduce warnings (#3085)
* build(deps-dev): bump ruff from 0.9.2 to 0.9.6 Bumps [ruff](https://github.com/astral-sh/ruff) from 0.9.2 to 0.9.6. - [Release notes](https://github.com/astral-sh/ruff/releases) - [Changelog](https://github.com/astral-sh/ruff/blob/main/CHANGELOG.md) - [Commits](astral-sh/ruff@0.9.2...0.9.6) --- updated-dependencies: - dependency-name: ruff dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> * add readthedocs sphynx.configuration * replace ConjunctiveGraph() with Dataset() in tests * tidy some notation * align black version * fix black & ruff * poetry --check -> poetry-check --lock * more CG -> Datasets * ruff * GC -> Dataset --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
1 parent 7d1f4c7 commit 8bbb30d

22 files changed

+159
-160
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ repos:
1414
args: ["--fix"]
1515
- repo: https://github.com/psf/black-pre-commit-mirror
1616
# WARNING: Black version should be the same as in `pyproject.toml`
17-
rev: "25.1.0"
17+
rev: "24.4.2"
1818
hooks:
1919
- id: black
2020
pass_filenames: false
@@ -24,6 +24,5 @@ repos:
2424
rev: 2.1.1
2525
hooks:
2626
- id: poetry-check
27-
- id: poetry-lock
2827
# sadly `--no-update` does not work on pre-commit.ci
29-
args: ["--check"]
28+
args: ["--lock"]

rdflib/plugins/parsers/notation3.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757

5858
from rdflib.compat import long_type
5959
from rdflib.exceptions import ParserError
60-
from rdflib.graph import ConjunctiveGraph, Graph, QuotedGraph
60+
from rdflib.graph import Dataset, Graph, QuotedGraph
6161
from rdflib.term import (
6262
_XSD_PFX,
6363
BNode,
@@ -2047,7 +2047,7 @@ def parse( # type: ignore[override]
20472047
elif not fa:
20482048
raise ParserError("Cannot parse N3 into non-formula-aware store.")
20492049

2050-
conj_graph = ConjunctiveGraph(store=graph.store)
2050+
conj_graph = Dataset(store=graph.store)
20512051
conj_graph.default_context = graph # TODO: CG __init__ should have a
20522052
# default_context arg
20532053
# TODO: update N3Processor so that it can use conj_graph as the sink

test/test_graph/test_diff.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import rdflib
1010
from rdflib import Graph
1111
from rdflib.compare import graph_diff
12-
from rdflib.graph import ConjunctiveGraph, Dataset
12+
from rdflib.graph import Dataset
1313
from rdflib.namespace import FOAF, RDF
1414
from rdflib.term import BNode, Literal
1515
from test.utils import (
@@ -111,7 +111,7 @@ def as_element_set(self, value: _ElementSetTypeOrStr) -> _ElementSetType:
111111
if isinstance(value, str):
112112
graph = self.graph_type()
113113
graph.parse(data=value, format=self.format)
114-
if isinstance(graph, ConjunctiveGraph):
114+
if isinstance(graph, Dataset):
115115
return GraphHelper.quad_set(graph, BNodeHandling.COLLAPSE)
116116
else:
117117
return GraphHelper.triple_set(graph, BNodeHandling.COLLAPSE)

test/test_graph/test_graph_context.py

Lines changed: 34 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -291,71 +291,63 @@ def test_triples(self):
291291

292292
for c in [graph, self.graph.get_context(c1)]:
293293
# unbound subjects
294-
asserte(set(c.subjects(likes, pizza)), set((michel, tarek)))
295-
asserte(set(c.subjects(hates, pizza)), set((bob,)))
296-
asserte(set(c.subjects(likes, cheese)), set([tarek, bob, michel]))
294+
asserte(set(c.subjects(likes, pizza)), {michel, tarek})
295+
asserte(set(c.subjects(hates, pizza)), {bob})
296+
asserte(set(c.subjects(likes, cheese)), {tarek, bob, michel})
297297
asserte(set(c.subjects(hates, cheese)), set())
298298

299299
# unbound objects
300-
asserte(set(c.objects(michel, likes)), set([cheese, pizza]))
301-
asserte(set(c.objects(tarek, likes)), set([cheese, pizza]))
302-
asserte(set(c.objects(bob, hates)), set([michel, pizza]))
303-
asserte(set(c.objects(bob, likes)), set([cheese]))
300+
asserte(set(c.objects(michel, likes)), {cheese, pizza})
301+
asserte(set(c.objects(tarek, likes)), {cheese, pizza})
302+
asserte(set(c.objects(bob, hates)), {michel, pizza})
303+
asserte(set(c.objects(bob, likes)), {cheese})
304304

305305
# unbound predicates
306-
asserte(set(c.predicates(michel, cheese)), set([likes]))
307-
asserte(set(c.predicates(tarek, cheese)), set([likes]))
308-
asserte(set(c.predicates(bob, pizza)), set([hates]))
309-
asserte(set(c.predicates(bob, michel)), set([hates]))
306+
asserte(set(c.predicates(michel, cheese)), {likes})
307+
asserte(set(c.predicates(tarek, cheese)), {likes})
308+
asserte(set(c.predicates(bob, pizza)), {hates})
309+
asserte(set(c.predicates(bob, michel)), {hates})
310310

311-
asserte(set(c.subject_objects(hates)), set([(bob, pizza), (bob, michel)]))
311+
asserte(set(c.subject_objects(hates)), {(bob, pizza), (bob, michel)})
312312
asserte(
313313
set(c.subject_objects(likes)),
314-
set(
315-
[
316-
(tarek, cheese),
317-
(michel, cheese),
318-
(michel, pizza),
319-
(bob, cheese),
320-
(tarek, pizza),
321-
]
322-
),
314+
{
315+
(tarek, cheese),
316+
(michel, cheese),
317+
(michel, pizza),
318+
(bob, cheese),
319+
(tarek, pizza),
320+
},
323321
)
324322

325-
asserte(
326-
set(c.predicate_objects(michel)), set([(likes, cheese), (likes, pizza)])
327-
)
323+
asserte(set(c.predicate_objects(michel)), {(likes, cheese), (likes, pizza)})
328324
asserte(
329325
set(c.predicate_objects(bob)),
330-
set([(likes, cheese), (hates, pizza), (hates, michel)]),
331-
)
332-
asserte(
333-
set(c.predicate_objects(tarek)), set([(likes, cheese), (likes, pizza)])
326+
{(likes, cheese), (hates, pizza), (hates, michel)},
334327
)
328+
asserte(set(c.predicate_objects(tarek)), {(likes, cheese), (likes, pizza)})
335329

336330
asserte(
337331
set(c.subject_predicates(pizza)),
338-
set([(bob, hates), (tarek, likes), (michel, likes)]),
332+
{(bob, hates), (tarek, likes), (michel, likes)},
339333
)
340334
asserte(
341335
set(c.subject_predicates(cheese)),
342-
set([(bob, likes), (tarek, likes), (michel, likes)]),
336+
{(bob, likes), (tarek, likes), (michel, likes)},
343337
)
344-
asserte(set(c.subject_predicates(michel)), set([(bob, hates)]))
338+
asserte(set(c.subject_predicates(michel)), {(bob, hates)})
345339

346340
asserte(
347341
set(c),
348-
set(
349-
[
350-
(bob, hates, michel),
351-
(bob, likes, cheese),
352-
(tarek, likes, pizza),
353-
(michel, likes, pizza),
354-
(michel, likes, cheese),
355-
(bob, hates, pizza),
356-
(tarek, likes, cheese),
357-
]
358-
),
342+
{
343+
(bob, hates, michel),
344+
(bob, likes, cheese),
345+
(tarek, likes, pizza),
346+
(michel, likes, pizza),
347+
(michel, likes, cheese),
348+
(bob, hates, pizza),
349+
(tarek, likes, cheese),
350+
},
359351
)
360352

361353
# remove stuff and make sure the graph is empty again

test/test_graph/test_graph_formula.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import pytest
55

66
from rdflib import RDF, RDFS, BNode, URIRef, Variable, plugin
7-
from rdflib.graph import ConjunctiveGraph, QuotedGraph
7+
from rdflib.graph import Dataset, QuotedGraph
88

99
implies = URIRef("http://www.w3.org/2000/10/swap/log#implies")
1010
testN3 = """
@@ -21,7 +21,7 @@
2121

2222
def checkFormulaStore(store="default", configString=None): # noqa: N802, N803
2323
try:
24-
g = ConjunctiveGraph(store=store)
24+
g = Dataset(store=store)
2525
except ImportError:
2626
pytest.skip("Dependencies for store '%s' not available!" % store)
2727

@@ -48,7 +48,7 @@ def checkFormulaStore(store="default", configString=None): # noqa: N802, N803
4848
d = URIRef("http://test/d")
4949
v = Variable("y")
5050

51-
universe = ConjunctiveGraph(g.store)
51+
universe = Dataset(g.store)
5252

5353
# test formula as terms
5454
assert len(list(universe.triples((formulaA, implies, formulaB)))) == 1

test/test_graph/test_namespace_rebinding.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22

3-
from rdflib import ConjunctiveGraph, Graph, Literal
3+
from rdflib import Dataset, Graph, Literal
44
from rdflib.namespace import OWL, Namespace, NamespaceManager
55
from rdflib.plugins.stores.memory import Memory
66
from rdflib.term import URIRef
@@ -292,12 +292,11 @@ def test_multigraph_bindings():
292292
assert list(g1.namespaces()) == [("friend-of-a-friend", foaf1_uri)]
293293

294294
# Including newly-created objects that use the store
295-
cg = ConjunctiveGraph(store=store)
295+
cg = Dataset(store=store, default_union=True)
296296
cg.namespace_manager = NamespaceManager(cg, bind_namespaces="core")
297297

298298
assert ("foaf", foaf1_uri) not in list(cg.namespaces())
299299
assert ("friend-of-a-friend", foaf1_uri) in list(cg.namespaces())
300-
301300
assert len(list(g1.namespaces())) == 6
302301
assert len(list(g2.namespaces())) == 6
303302
assert len(list(cg.namespaces())) == 6

test/test_n3.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import pytest
66

7-
from rdflib.graph import ConjunctiveGraph, Graph
7+
from rdflib.graph import Dataset, Graph
88
from rdflib.plugins.parsers.notation3 import BadSyntax, exponent_syntax
99
from rdflib.term import Literal, URIRef
1010
from test import TEST_DIR
@@ -44,7 +44,7 @@
4444
n3:predicate :p;
4545
n3:object :y ] a log:Truth}.
4646
47-
# Needs more thought ... ideally, we have the implcit AND rules of
47+
# Needs more thought ... ideally, we have the implicit AND rules of
4848
# juxtaposition (introduction and elimination)
4949
5050
{
@@ -125,9 +125,9 @@ def test_base_serialize(self):
125125
)
126126
s = g.serialize(base="http://example.com/", format="n3", encoding="latin-1")
127127
assert b"<people/Bob>" in s
128-
g2 = ConjunctiveGraph()
129-
g2.parse(data=s, publicID="http://example.com/", format="n3")
130-
assert list(g) == list(g2)
128+
g2 = Dataset()
129+
g2.parse(data=s, format="n3")
130+
assert list(g) == list(g2.triples((None, None, None)))
131131

132132
def test_issue23(self):
133133
input = """<http://example.com/article1> <http://example.com/title> "this word is in \\u201Cquotes\\u201D"."""
@@ -195,24 +195,24 @@ def test_dot_in_prefix(self):
195195
)
196196

197197
def test_model(self):
198-
g = ConjunctiveGraph()
198+
g = Dataset()
199199
g.parse(data=test_data, format="n3")
200200
i = 0
201-
for s, p, o in g:
201+
for s, p, o, c in g:
202202
if isinstance(s, Graph):
203203
i += 1
204204
assert i == 3
205-
assert len(list(g.contexts())) == 13
205+
assert len(list(g.graphs())) == 13
206206

207207
g.close()
208208

209209
def test_quoted_serialization(self):
210-
g = ConjunctiveGraph()
210+
g = Dataset()
211211
g.parse(data=test_data, format="n3")
212212
g.serialize(format="n3")
213213

214214
def test_parse(self):
215-
g = ConjunctiveGraph()
215+
g = Dataset()
216216
try:
217217
g.parse(
218218
"http://groups.csail.mit.edu/dig/2005/09/rein/examples/troop42-policy.n3",
@@ -229,14 +229,14 @@ def test_single_quoted_literals(self):
229229

230230
for data in test_data:
231231
# N3 doesn't accept single quotes around string literals
232-
g = ConjunctiveGraph()
232+
g = Dataset()
233233
with pytest.raises(BadSyntax):
234234
g.parse(data=data, format="n3")
235235

236-
g = ConjunctiveGraph()
236+
g = Dataset()
237237
g.parse(data=data, format="turtle")
238238
assert len(g) == 1
239-
for _, _, o in g:
239+
for _, _, o, c in g:
240240
assert o == Literal("o")
241241

242242
def test_empty_prefix(self):

test/test_parsers/test_empty_xml_base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
and RDF/XML dependence on it
66
"""
77

8-
from rdflib.graph import ConjunctiveGraph
8+
from rdflib.graph import Dataset
99
from rdflib.namespace import FOAF, RDF
1010
from rdflib.term import URIRef
1111

@@ -36,7 +36,7 @@
3636

3737
class TestEmptyBase:
3838
def test_empty_base_ref(self):
39-
self.graph = ConjunctiveGraph()
39+
self.graph = Dataset()
4040
self.graph.parse(data=test_data, publicID=baseUri, format="xml")
4141
assert (
4242
len(list(self.graph)) > 0
@@ -50,7 +50,7 @@ def test_empty_base_ref(self):
5050

5151
class TestRelativeBase:
5252
def test_relative_base_ref(self):
53-
self.graph = ConjunctiveGraph()
53+
self.graph = Dataset()
5454
self.graph.parse(data=test_data2, publicID=baseUri2, format="xml")
5555
assert (
5656
len(self.graph) > 0

0 commit comments

Comments
 (0)