Why a super() statement ?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Why a super() statement ?

srfpala
In   Precord  text p 15    Show a BitMap uses:

super(MyFrame, self).__init__(parent, id, title, pos, size, style, name)

The above statement seems superfluous, and ASAIK offers nothing new to the App.
Why is it needed ?
Bob

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/a46dd5fb-8fe1-4af4-9a87-ddc521907761%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Why a super() statement ?

Mike Driscoll-2
It's not needed. But it doesn't hurt anything either. Also I think it is recommended to use super() that way I'm Python 3.

So while it's not needed it is conventional to use it in the latest version of Python.

Mike

On Sat, Jun 22, 2019, 6:29 PM srfpala <[hidden email]> wrote:
In   Precord  text p 15    Show a BitMap uses:

super(MyFrame, self).__init__(parent, id, title, pos, size, style, name)

The above statement seems superfluous, and ASAIK offers nothing new to the App.
Why is it needed ?
Bob

--

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/CAO4gEAsn9%3D1ujzrAcpAUVmWPv_nMrL8HqZH-oNAFKPf9F9mntA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Why a super() statement ?

Gerhard Schmidt
Hi,

it might not be needed there but it's needed to ensure that all __init__
methods of any superclasses are called.

Not calling super in all __init__ methods might break initialization
when deriving from multiple classes way down the hierarchy.

an example

you have a class A, Class B derived from A and Class C derived from
Class B and a Class D that has nothing to do with class A or B.

The __init__ method of class C call super which calls the B.__init__, in
B.__init__ super is called again and A.__init__ is called. if A.__init__
doesn't call super the execution goes back to B.__init__ and C.__init__
after the methods are finished, but D.__init__ is never called because
the super call in A.__init__ will trigger that.

That's what in experienced in one of my projects I'm migrated from
python 2 to python3. I might be wrong here, but that's what I'm
experiencing.

Before super you called the __init__ method of any class you derived
from directly. Now the super call has to handle that.

Regards
    Estartu

Am 23.06.19 um 02:13 schrieb Mike Driscoll:

> It's not needed. But it doesn't hurt anything either. Also I think it is
> recommended to use super() that way I'm Python 3.
>
> So while it's not needed it is conventional to use it in the latest
> version of Python.
>
> Mike
>
> On Sat, Jun 22, 2019, 6:29 PM srfpala <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>     In   Precord  text p 15    Show a BitMap uses:
>
>     super(MyFrame, self).__init__(parent, id, title, pos, size, style, name)
>
>     The above statement seems superfluous, and ASAIK offers nothing new
>     to the App.
>     Why is it needed ?
>     Bob
>
>     --
>
> --
> You received this message because you are subscribed to the Google
> Groups "wxPython-users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to [hidden email]
> <mailto:[hidden email]>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/wxpython-users/CAO4gEAsn9%3D1ujzrAcpAUVmWPv_nMrL8HqZH-oNAFKPf9F9mntA%40mail.gmail.com
> <https://groups.google.com/d/msgid/wxpython-users/CAO4gEAsn9%3D1ujzrAcpAUVmWPv_nMrL8HqZH-oNAFKPf9F9mntA%40mail.gmail.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

--
----------------------------------------------------------------------------
Gerhard Schmidt    | http://www.augusta.de/~estartu/    |
Fischbachweg 3     |                                    | PGP Public Key
86856 Hiltenfingen | JabberID: [hidden email]       |  auf Anfrage/
Tel: 08232 77 36 4 |                                    |   on request
Fax: 08232 77 36 3 |                                    |

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/a436275c-56f5-70ed-e3bb-7513c9c76be9%40augusta.de.
For more options, visit https://groups.google.com/d/optout.

estartu.vcf (240 bytes) Download Attachment
signature.asc (849 bytes) Download Attachment