Skip to content

Resource inheritance removes class level variables #2

@dharvey-consbio

Description

@dharvey-consbio

When trying to extend FeatureLayerResource:

from restle.actions import Action
from restle.fields import TextField
from restle.resources import Resource


class ParentResource(Resource):
    text_field = TextField()
    query_field = Action(...)


class ChildResourceOne(ParentResource):
    pass  # text_field present, query_field unavailable


class ChildResourceTwo(ParentResource):
    # Class definition fails because query_field is removed
    query_field = ParentResource.query_field

There is no way to inherit query_field in the usual manner of Python class inheritance.

Current workaround: put Action(...) into a constant that can be referenced in both the parent and the child classes:

from restle.actions import Action
from restle.fields import TextField
from restle.resources import Resource

QUERY_ACTION = Action(...)


class ParentResource(Resource):
    text_field = TextField()
    query_field = QUERY_ACTION


class ChildResourceOne(ParentResource):
    query_field = QUERY_ACTION

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