Page 1 of 1

Weird inheritance assertion difference between embedded library and interpreter

Posted: Tue Dec 14, 2021 8:30 am
by yanh
Hey all,

I am trying to use the static library in example/embedding to try and run on a unix system.

When I do so, the following code throws an assertion error:

Code: Select all

class _Environ(dict):

    def __init__(self):
        dict.__init__(self) <------ That is the line that fails   :_(   :_(
        env = uctypes.struct(_environ_ptr.get(), _ENV_STRUCT)
        for i in range(4096):
            if int(env.arr[i]) == 0:
                break
            s = uctypes.bytes_at(env.arr[i]).decode()
            k, v = s.split("=", 1)
            dict.__setitem__(self, k, v)

    def __setitem__(self, k, v):
        putenv(k, v)
        dict.__setitem__(self, k, v)


environ = _Environ()
The assertion that occurs is on py/objdict.c - line 375,

Code: Select all

mp_check_self(mp_obj_is_dict_or_ordereddict(..))
When I run this with the `port/unix` however, this works just fine...


Can anyone please shed some light on this?

Re: Weird inheritance assertion difference between embedded library and interpreter

Posted: Tue Dec 14, 2021 9:01 am
by stijn
Don't you need super().__init__(self) instead of dict.__init__(self)? (apart from that: not sure if subclassing builtins is actually fully supported)