← index #7957Issue #145
Off-topic · high · value 0.294
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

Q: Recommended way to look an object method taking into account base classes, C-defined methods, without side effects

closedby pfalconopened 2014-01-11updated 2014-03-18

So, what I'd like to do is:

  1. Get a method in an object (not interested in data member by the same name).
  2. Should consider both ->methods array and dict of dynamic type.
  3. If method not found, no exception throwing, etc.

Grepping headers by "method" I found rt_load_method(), which seemed cover 1&2, but throws exception on not found, so I proceeded to factor out it into non-throwing function.

But looking at objtype.c:class_make_new(), it uses mp_obj_class_lookup(), but that definitely doesn't consider ->methods.

So, what's the recommended way?

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