'Try to locate the appropriate derived class dynamically, and cast
the pointer accordingly.'

@classmethod
def from_pyobject_ptr(cls, gdbval):

    try:
        p = PyObjectPtr(gdbval)
        cls = cls.subclass_from_type(p.type())
        return cls(gdbval, cast_to=cls.get_gdb_type())
    except RuntimeError:
        pass
    return cls(gdbval)
