Types refactor and inheritance
Merged
SA
19d ago+8102+8102+0123456789012345678901234567890123456789-2545-2545-0123456789012345678901234567890123456789
proposed refactor of types to make inheritance easier, and basic inheritance
Summary by cubic
Reworks how types are modeled and adds class inheritance for user classes.
Native types and exception classes now come from one generated table (native_types! in types/native.rs), replacing BuiltinType and the inline ExcType builtin. py_type() returns a TypeRef that covers both native types and user classes, so isinstance(), except matching, and type() share a single implementation. Numeric binary operators skip the class lookup when both operands are immediate, and builtin type names resolve by binary search over an inline sorted table.
New Features
- Classes accept bases with C3 MRO,
issubclass(), andobject.__new__/__init__/__init_subclass__, matching CPython's error and copy semantics. Class keywords reach__init_subclass__,obj.__class__can be reassigned, and reflected operators and==prefer the subclass. Zero-argumentsuper()is deferred until descriptors land; base methods are called explicitly. - Native type class attributes and class methods (like
date.minandPath.cwd()) now go through the table. - Native types and exceptions can't be used as bases yet; they raise
TypeError.
Migration
- Old dumps still load: legacy type shapes are read back, and type names and postcard indices stay pinned. A pinned fixture stores pre-refactor types as dump and hash keys so it can't be regenerated.