RDFLib / rdflib

RDFLib is a Python library for working with RDF, a simple yet powerful language for representing information.
https://rdflib.readthedocs.org
BSD 3-Clause "New" or "Revised" License
2.15k stars 555 forks source link

Prevent Collection from adding 'rdf:nil rdf:rest rdf:nil.' triples #2818

Closed progval closed 2 months ago

progval commented 2 months ago

Summary of changes

Creating 'Collection(graph, RDF.nil)' used to add a 'rdf:nil rdf:rest rdf:nil.' triple to the graph, which turned the empty list into an infinite list.

This was a side-effect of unconditionally appending 'seq' to the collection, which is not possible when the collection is 'nil' without ill side-effects.

This commit makes the append conditional; and also checks the collection is non-empty in case the user explicitly tries to add item to the empty list

Checklist

coveralls commented 2 months ago

Coverage Status

coverage: 90.635%. first build when pulling 6e65136305158bb845887e03561ac905166b4d23 on progval:collection-empty-list into 46695eb291adeba5e112f92e0bcd9d8ed1c35243 on RDFLib:main.

ashleysommer commented 2 months ago

There's an odd failing test now, weirdly its the same SPARQL test that is failing in #2796 that is completely unrelated to this PR.

ashleysommer commented 2 months ago

That sporadic test is no longer failing, this can merge.