Skip to content

Commit

Permalink
Another fix for super.
Browse files Browse the repository at this point in the history
  • Loading branch information
kochelmonster committed Jan 18, 2022
1 parent 72aee66 commit ab150cd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,21 @@ def plugin(self, call_order):
class Child(Mixin, Base):
pass

class GrandChild(Child):
pass

call_order = []
mixed = Child(call_order)
autoTester.check (call_order)

call_order = []
mixed.plugin(call_order)
autoTester.check (call_order)

call_order = []
mixed = GrandChild(call_order)
autoTester.check (call_order)

call_order = []
mixed.plugin(call_order)
autoTester.check (call_order)
2 changes: 1 addition & 1 deletion transcrypt/modules/org/transcrypt/__builtin__.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function create_next_super(cls) {
return function(methodName) {
while(index < mro.length) {
let base = mro[index++];
if (methodName in base)
if (methodName in base.__class_attribs__)
return base;
}
throw new Exception ('Superclass method not found'); // !!! Improve!
Expand Down
3 changes: 3 additions & 0 deletions transcrypt/modules/org/transcrypt/__core__.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ function _to_python_descriptor(instance, descript) {
export var py_metatype = {
__name__: 'type',
__bases__: [],
__class_attribs__: {__init__: true},

// Overridable class creation worker
__new__: function (meta, name, bases, attribs) {
Expand Down Expand Up @@ -233,6 +234,7 @@ export var py_metatype = {
cls.__metaclass__ = meta;
cls.__name__ = name.startsWith ('py_') ? name.slice (3) : name;
cls.__bases__ = bases;
cls.__class_attribs__ = attribs;

if (! ("__init__" in attribs)) {
attribs["__init__"] = function() {
Expand Down Expand Up @@ -271,6 +273,7 @@ export var object = {

__metaclass__: py_metatype, // By default, all classes have metaclass type, since they derive from object
__name__: 'object',
__class_attribs__: {__init__: true},
__bases__: [],

// Object creator function, is inherited by all classes (so could be global)
Expand Down

0 comments on commit ab150cd

Please sign in to comment.