Skip to content

Use simpler form of super() where possible #453

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

Merged
merged 3 commits into from
Mar 29, 2024

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
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy