Skip to content

Commit

Permalink
correctly return the length of rdf:List for RDFLib#223
Browse files Browse the repository at this point in the history
  • Loading branch information
William Waites committed Jan 19, 2017
1 parent a972e7b commit 10935dd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
7 changes: 1 addition & 6 deletions rdflib/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,7 @@ def _get_container(self, index):

def __len__(self):
"""length of items in collection."""
count = 0
links = set()
for item in self.graph.items(self.uri):
links.add(item)
count += 1
return count
return len(list(self.graph.items(self.uri)))

def index(self, item):
"""
Expand Down
7 changes: 4 additions & 3 deletions test/test_issue223.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ def test_collection_with_duplicates():
g = Graph().parse(data=ttl, format="turtle")
for _,_,o in g.triples((URIRef("http://example.org/s"), URIRef("http://example.org/p"), None)):
break
c = list(Collection(g, o))
assert c == list(URIRef("http://example.org/" + x) for x in ["a", "b", "a"])

c = Collection(g, o)
assert list(c) == list(URIRef("http://example.org/" + x) for x in ["a", "b", "a"])
assert len(c) == 3

if __name__ == '__main__':
test_collection_with_duplicates()

0 comments on commit 10935dd

Please sign in to comment.