From ab150cdea872e945950d53f1d276ce76e42619ce Mon Sep 17 00:00:00 2001 From: kochelmonster Date: Tue, 18 Jan 2022 01:50:04 +0100 Subject: [PATCH] Another fix for super. --- .../transcrypt/builtin_super/__init__.py | 11 +++++++++++ transcrypt/modules/org/transcrypt/__builtin__.js | 2 +- transcrypt/modules/org/transcrypt/__core__.js | 3 +++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/transcrypt/development/automated_tests/transcrypt/builtin_super/__init__.py b/transcrypt/development/automated_tests/transcrypt/builtin_super/__init__.py index fd06958a..df07ee06 100644 --- a/transcrypt/development/automated_tests/transcrypt/builtin_super/__init__.py +++ b/transcrypt/development/automated_tests/transcrypt/builtin_super/__init__.py @@ -149,6 +149,9 @@ def plugin(self, call_order): class Child(Mixin, Base): pass + class GrandChild(Child): + pass + call_order = [] mixed = Child(call_order) autoTester.check (call_order) @@ -156,3 +159,11 @@ class Child(Mixin, Base): 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) diff --git a/transcrypt/modules/org/transcrypt/__builtin__.js b/transcrypt/modules/org/transcrypt/__builtin__.js index 5b479516..e3678120 100644 --- a/transcrypt/modules/org/transcrypt/__builtin__.js +++ b/transcrypt/modules/org/transcrypt/__builtin__.js @@ -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! diff --git a/transcrypt/modules/org/transcrypt/__core__.js b/transcrypt/modules/org/transcrypt/__core__.js index f98235dd..4a73b1cc 100644 --- a/transcrypt/modules/org/transcrypt/__core__.js +++ b/transcrypt/modules/org/transcrypt/__core__.js @@ -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) { @@ -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() { @@ -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)