diff --git a/rdflib/compare.py b/rdflib/compare.py index ec4bd44eb..7c808b1a5 100644 --- a/rdflib/compare.py +++ b/rdflib/compare.py @@ -453,13 +453,13 @@ def _traces( elif best_score > color_score: # prune this branch. if stats is not None: - stats["prunings"] += 1 # type: ignore[operator] + stats["prunings"] = int(stats.get("prunings", 0)) + 1 elif experimental_score != best_experimental_score: best.append(refined_coloring) else: # prune this branch. if stats is not None: - stats["prunings"] += 1 # type: ignore[operator] + stats["prunings"] = int(stats.get("prunings", 0)) + 1 discrete: list[list[Color]] = [x for x in best if self._discrete(x)] if len(discrete) == 0: best_score = None diff --git a/rdflib/plugins/parsers/jsonld.py b/rdflib/plugins/parsers/jsonld.py index f6574874d..0031c8662 100644 --- a/rdflib/plugins/parsers/jsonld.py +++ b/rdflib/plugins/parsers/jsonld.py @@ -662,6 +662,7 @@ def _add_list( continue if rest: + # type error: Statement is unreachable graph.add((subj, RDF.rest, rest)) subj = rest diff --git a/rdflib/plugins/serializers/patch.py b/rdflib/plugins/serializers/patch.py index 58928c6a0..da32ead97 100644 --- a/rdflib/plugins/serializers/patch.py +++ b/rdflib/plugins/serializers/patch.py @@ -2,7 +2,6 @@ import warnings from typing import IO, Any -from uuid import uuid4 from rdflib import Dataset from rdflib.plugins.serializers.nquads import _nq_row @@ -51,8 +50,6 @@ def serialize( target = kwargs.get("target") header_id = kwargs.get("header_id") header_prev = kwargs.get("header_prev") - if not header_id: - header_id = f"uuid:{uuid4()}" encoding = self.encoding if base is not None: warnings.warn("PatchSerializer does not support base.") @@ -63,9 +60,10 @@ def serialize( ) def write_header(): - stream.write(f"H id <{header_id}> .\n".encode(encoding, "replace")) + if header_id: + stream.write(f"H id <{header_id}> .\n".encode(encoding, "replace")) if header_prev: - stream.write(f"H prev <{header_prev}>\n".encode(encoding, "replace")) + stream.write(f"H prev <{header_prev}> .\n".encode(encoding, "replace")) stream.write("TX .\n".encode(encoding, "replace")) def write_triples(contexts, op_code, use_passed_contexts=False): diff --git a/rdflib/store.py b/rdflib/store.py index f31902547..51d6d8422 100644 --- a/rdflib/store.py +++ b/rdflib/store.py @@ -121,6 +121,8 @@ def register(self, object: Any, id: str) -> None: def loads(self, s: bytes) -> Node: up = Unpickler(BytesIO(s)) + # NOTE on type error: https://github.com/python/mypy/issues/2427 + # type error: Cannot assign to a method up.persistent_load = self._get_object try: return up.load() @@ -130,6 +132,8 @@ def loads(self, s: bytes) -> Node: def dumps(self, obj: Node, protocol: Any | None = None, bin: Any | None = None): src = BytesIO() p = Pickler(src) + # NOTE on type error: https://github.com/python/mypy/issues/2427 + # type error: Cannot assign to a method p.persistent_id = self._get_ids p.dump(obj) return src.getvalue() diff --git a/test/test_serializers/test_serializer_patch.py b/test/test_serializers/test_serializer_patch.py index 6d8a05055..c0c44ca87 100644 --- a/test/test_serializers/test_serializer_patch.py +++ b/test/test_serializers/test_serializer_patch.py @@ -176,3 +176,18 @@ def test_prev_header(): ) result = ds.serialize(format="patch", operation="add", header_prev="uuid:123") assert """H prev """ in result + + +def test_no_headers(): + ds = Dataset() + ds.add( + ( + URIRef("http://example.org/subject1"), + URIRef("http://example.org/predicate2"), + Literal("object2"), + ) + ) + result = ds.serialize(format="patch", operation="add") + lines = result.split("\n") + for line in lines: + assert not line.startswith("H ")