Skip to content

Conversation

almarklein
Copy link
Collaborator

@almarklein almarklein commented Mar 27, 2024

These caught my eye in my earlier review. Simple fix that makes the code a bit simplere / easier to read, but possibly also avoids bugs.


Context:

class Foo:    
    def __init__(self):
        print("init Foo")

class Bar(Foo):
    def __init__(self):
        super().__init__()
        print("init Bar")

class Spam(Bar):
    def __init__(self):
        super().__init__()
        print("init Spam")

Spam()

Produces:

init Foo
init Bar
init Spam

Replacing the super() in Spam with super(Spam, self).__init__() produces the same result.
But if it is replaced with super(Foo, self).__init__(), it produces:

init Foo
init Spam

@almarklein
Copy link
Collaborator Author

Also looking into Subplot, which has multiple inheritance.

For reference:

class Foo:
    def __init__(self):
        super().__init__()
        print("init Foo")

class Bar():
    def __init__(self):
        super().__init__()
        print("init Bar")

class Spam(Bar, Foo):
    def __init__(self):
        super().__init__()
        print("init Spam")

Spam()

Produces:

init Foo
init Bar
init Spam

@almarklein
Copy link
Collaborator Author

There's a lot of multiple inheritance when you get to the plots and graphics, and that results in some juggling with super and direct calls to SomeSuperclass.__init__. Will not burn my hands on that right now. Let's keep this pr small 😅

@kushalkolar kushalkolar marked this pull request as ready for review March 28, 2024 02:11
@kushalkolar kushalkolar requested a review from clewis7 as a code owner March 28, 2024 02:11
@kushalkolar kushalkolar merged commit 0021652 into fastplotlib:main Mar 29, 2024
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

Successfully merging this pull request may close these issues.

2 participants