← index #1159PR #528
Likely Duplicate · medium · value 0.857
QUERY · ISSUE

Inheritance for native types is not supported

openby pfalconopened 2015-03-16updated 2018-12-15
enhancement

Default load_attr implementation (as used for all native types) doesn't take type inheritance (->bases_tuple) into account. I'm working on OrderedDict implementation, and it inherits most of its methods from dict, but adds few (well, 1) new method. Of course, this new method can be ignored, and old trick of putting the same .locals_dict to both types can be used. But I wanted to look into making truly inheritable methods, which requires setting custom .load_attr type method. And we already have implementation of this method which takes inheritance into account - for user classes/instances. But trying to use it, it assumes that object whose attr is being looked up is instance, so making it work with native objects means adding even more conditions to existing bunch of those (and which are already pretty mind-boggling). Another alternative is to make clean, "optimized" inheritance-friendly .load_attr for native types, but that means code duplication (and refactoring of existing code paths, factoring out functions, which means more stack usage, etc.)

Any thoughts?

CANDIDATE · PULL REQUEST

Initial support for subclassing native types

mergedby pfalconopened 2014-04-29updated 2014-10-09

Probably not worth merging yet, but if you have time, I'd appreciate comments.

Unfortunately, this uncovers a bug with tests/misc/features.py, which again looks like some memory issue:

micropython: ../py/emitglue.c:155: mp_make_function_from_raw_code: Assertion `0' failed.

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