TranscryptOrg / Transcrypt

Python 3.9 to JavaScript compiler - Lean, fast, open!
https://www.transcrypt.org
Apache License 2.0
2.86k stars 215 forks source link

A method in the second base class is not called even when the first base class is empty. #857

Open chopin opened 1 year ago

chopin commented 1 year ago

Hi.

I found that a method in the second base class was not called when there was another base class in front of the second one. It seems that the first base class overrides the second one even when the first one has no method

Following is the code I tested:

class BaseClassA:
    def __init__(self, text):
        print('in __init__ in BaseClassA')
        self.text= text
class BaseClassB:
    pass
class ClassC(BaseClassB, BaseClassA):
    pass
def main():
    obj= ClassC('hello')
    print('obj.text= ', obj.text)
if __name__ == '__main__':
    main()

The output in CPython:

in __init__ in BaseClassA
obj.text=  hello

The output in Transcrypt:

obj.text=  None

I think that the first base class should override ONLY WHEN it has a method. It looks like a bug in class inheritance.

Thanks.