[SOLVED]const void * parent (_mp_obj_type_t)
Posted: Mon Mar 26, 2018 9:07 pm
What is this supposed to be used for?
Please see the new forum at
https://forum.micropython.org/
It's defined in _mp_obj_type_t
Code: Select all
// One of disjoint protocols (interfaces), like mp_stream_p_t, etc.
const void *protocol;
// A pointer to the parents of this type:
// - 0 parents: pointer is NULL (object is implicitly the single parent)
// - 1 parent: a pointer to the type of that parent
// - 2 or more parents: pointer to a tuple object containing the parent types
const void *parent;
// A dict mapping qstrs to objects local methods/constants/etc.
struct _mp_obj_dict_t *locals_dict;
};
Code: Select all
#if MICROPY_PY_COLLECTIONS_ORDEREDDICT
const mp_obj_type_t mp_type_ordereddict = {
{ &mp_type_type },
.name = MP_QSTR_OrderedDict,
.print = dict_print,
.make_new = dict_make_new,
.unary_op = dict_unary_op,
.binary_op = dict_binary_op,
.subscr = dict_subscr,
.getiter = dict_getiter,
.parent = &mp_type_dict,
.locals_dict = (mp_obj_dict_t*)&dict_locals_dict,
};
#endif
Code: Select all
class Employee(Person):
Code: Select all
class SubClass(BaseClass1, BaseClass2):
Thanks. That's what I thought it was but good to make sure.dhylands wrote: ↑Mon Mar 26, 2018 9:35 pmWhen you use inheritance, parent will point to the parent object.
So if you were to declare:then the Employee class parent would point to the Person class.Code: Select all
class Employee(Person):
If you're using multiple inheritance:then parent will point to a tuple containing BaseClass1 and BaseClass2.Code: Select all
class SubClass(BaseClass1, BaseClass2):
Your example shows that OrderedDict is a subclass of dict.