Replies: 3 comments 1 reply
-
Micropython's implementation of In static mp_obj_t object___new__(mp_obj_t cls) {
if (!mp_obj_is_type(cls, &mp_type_type) || !mp_obj_is_instance_type((mp_obj_type_t *)MP_OBJ_TO_PTR(cls))) {
mp_raise_TypeError(MP_ERROR_TEXT("arg must be user-type"));
}
// This executes only "__new__" part of instance creation.
// TODO: This won't work well for classes with native bases.
// TODO: This is a hack, should be resolved along the lines of
// https://github.com/micropython/micropython/issues/606#issuecomment-43685883
const mp_obj_type_t *native_base;
return MP_OBJ_FROM_PTR(mp_obj_new_instance(MP_OBJ_TO_PTR(cls), &native_base));
} |
Beta Was this translation helpful? Give feedback.
-
OK, thanks for the clarification. Since micropython development is seems to be stalled and circuitpython does not support my ESP8266, I can better implement my own iterator class using a byte array as attribute to store the data. |
Beta Was this translation helpful? Give feedback.
-
Just a note, but from a software architecture POV this doesn't sound like the best idea, and a typcial place where instead of inheritance you'd use composition or extension functions etc. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I am creating a subclass of array.array with some additional functions to use the class for storing measured data.
At first I used
__init__(self, ..)
to create additional members but since__init__
is called too late in influence the creation of the array, I am now using__new__(cls)
.I have to distinguish between cpyhton and micropython for the call to
__new__
. My code:Creation of the array works fine under both cpython and micropython. But addressing array elements fails under micropython. The output I get is:
So when calling
len()
micropython does not recognises
to be an MeasurementArray. Indexing or calling len() on a standard array does work fine. Since this works as it should under cpython I have been going through the differences between cpython and micropython but I did not find a solution so far.Why does micropython fail on this code?
Beta Was this translation helpful? Give feedback.
All reactions