Skip to content

Memory store stores the resource object, not the semantic. #3338

@ticapix

Description

@ticapix

Hello,

I'm not sure how to describe the issue, so here is a sample code

from rdflib import FOAF, Graph, Literal, URIRef


class MyId(URIRef): ...


g = Graph()

g.add((MyId("subject"), FOAF.name, Literal("bob")))

print(g.serialize())

assert (MyId("subject"), FOAF.name, Literal("bob")) in g  # ok
assert (URIRef("subject"), FOAF.name, Literal("bob")) in g  # fails

And the output

@prefix foaf: <http://xmlns.com/foaf/0.1/> .

<subject> foaf:name "bob" .

I was expecting the second assert to be True because in both case I'm looking for the subject <subject>.

PS: on the why I'm subclassing URIRef, it's to leverage static type checking with mypy when my functions are expecting ids that carry a special meaning.

Is it the expected behavior and should I take care of always passing URIRef object ?

This fix the issue but is a bit cumbersome.

g.add((URIRef(MyId("subject")), FOAF.name, Literal("bob")))

print(g.serialize())

assert (URIRef(MyId("subject")), FOAF.name, Literal("bob")) in g  # ok
assert (URIRef("subject"), FOAF.name, Literal("bob")) in g  # ok

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions