Skip to content

Issue with classes inheriting from Resource #585

@dokamo

Description

@dokamo

When creating a class that inherits from Resource, any resource generated from inside the subclass is initialized as the subclass (not as Resource).

Exemple:

from rdflib import *
from rdflib.resource import Resource
from rdflib.namespace import RDF, FOAF

class Person( Resource ):

    def __init__(self, graph, subject):
        super(Person, self).__init__(graph, subject)
        self.add( RDF.type, FOAF.Person )

    def interest(self):
        return self.value( FOAF.interest ) # that's the point

g = Graph()
mike = Person( g, URIRef('http://example.com/mike' ) )
any = Resource( g, URIRef('http://example.com/any' ) )
mike.add( FOAF.interest, any)
interest = mike.interest() 
print g.serialize(format='turtle')

Outputs:

...
@prefix ns1: <http://xmlns.com/foaf/0.1/> .
<http://example.com/mike> a ns1:Person ;
    ns1:interest <http://example.com/any> .
<http://example.com/any> a ns1:Person .     <---- Who said that!?

Edit: rdflib version is 4.2.1

Cheers,
Marc

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions