Skip to content

Feature request: make join() return self.__class__ to support subclassing #64

Description

@kjxlstad

Currently, the JsonPointer.join() method always returns a JsonPointer instance, even when called from a subclass:

classPointer(jsonpointer.JsonPointer):
...
base=Pointer("/some/object")
end=Pointer("/actual/value")
full=base.join(end)
print(type(full))
# <class 'jsonpointer.JsonPointer'>

If join() (and probably other methods) instead returned instances of self.__class__ instead of JsonPointer normal behavior would stay the same while allowing subclasses to work as expected.

E.g. with join() as:

defjoin(self, suffix):
""" Returns a new JsonPointer with the given suffix append to this ptr """ifisinstance(suffix, self.__class__):
suffix_parts=suffix.partselifisinstance(suffix, str):
suffix_parts=self.__class__(suffix).partselse:
suffix_parts=suffixtry:
returnself.__class__.from_parts(chain(self.parts, suffix_parts))
except: # noqa E722raiseJsonPointerException("Invalid suffix")

You'd get:

print(type(JsonPointer("/some/object") /JsonPointer("/actual/value")))
# <class 'jsonpointer.JsonPointer'>print(type(Pointer("/some/object") /Pointer("/actual/value")))
# <class '__main__.Pointer'>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions