Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
chopin opened this issue Jun 17, 2023 · 0 comments

Comments

@chopin
Copy link

chopin commented Jun 17, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant