← index #7957Issue #3124
Related · medium · value 0.233
QUERY · ISSUE

mp_obj_class_lookup error

openby heixiaomaopened 2021-11-01updated 2021-11-06

After I rebuilt, there was a problem running the example. I don't know why

assertion "mp_obj_is_dict_or_ordereddict(MP_OBJ_FROM_PTR(type->locals_dict))" failed: file "/home/hxm/Desktop/lv_micropython/py/objtype.c", line 156, function: mp_obj_class_lookup
CANDIDATE · ISSUE

Unable to create builtin object from a subclass of a builtin

closedby MrSurlyopened 2017-05-31updated 2017-06-01

Using the baseline https://github.com/micropython/micropython-esp32/tree/esp32

Best explained with code:

class Y(dict): 
    pass
y = Y()
y[1] = 'one'
print(y)
dict(y)

Expected output (per CPython):

{1: 'one'}
{1: 'one'}

Actual output:

{1: 'one'}
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'int' object is not iterable

I dug into this a bit:

In py/objdict.c, dict_make_new calls dict_update, which incorrectly identifies the type of the parameter as being something other than a dict.

How bound dict methods work for object y (e.g. y.items()) is above my paygrade, but they do work. Nonetheless, I tried modifying MP_OBJ_IS_DICT_TYPE to call mp_obj_is_subclass_fast. This doesn't work -- it actually gets a different mp_obj_t pointer than what is passed to y.items(). While the error goes away, the dict returned from the dict(y) line above is empty, since it's looking for dict items in a class Y object.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied