Skip to content

Derived class __init__: __argnames__ definition not inherited #134

@ralphwetzel

Description

@ralphwetzel

The (familiar) setup:

image

app/__init__.pyj:

from control.item import TestA, TestB

class TestApp():
    def __init__(self):
        self.tA = TestA(id="A")
        self.tB = TestB(id="B")
        self.tA.out()
        self.tB.out()

x = TestApp()

control/item.pyj:

class TestA():
    def __init__(self, id):
        self.id = id
    def out(self):
        console.log(self.id)

class TestB(TestA):
    pass

Running test.jsresults in

A
[Object: null prototype] { id: 'B', [Symbol(kwargs-object)]: true }

... expressing that there's an issue with self.id in TestB.

Walking through the code I'm convinced this is due to the fact that
a) TestB is missing the __argnames__ definition that should have been inherited from TestA ...
b) ρσ_interpolate_kwargs thus executes the !f.__argnames__ case ...

function ρσ_interpolate_kwargs(f, supplied_args) {
    var has_prop, kwobj, args, prop;
    if (!f.__argnames__) {
        return f.apply(this, supplied_args);
    }
    has_prop = Object.prototype.hasOwnProperty;
    kwobj = supplied_args.pop();

c) and wrongly packs the provided parameters into arguments:

TestA/arguments at the end of ρσ_interpolate_kwargs:
image

TestB/argumentsat the end of ρσ_interpolate_kwargs:
image

Consequentially the initialization of self.id in TestB pulls the wrong parameter - generating the issue indicated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions