Hello,
I noticed that bultin types like list, set, dict, tuple don't seem to adhere to
the convention of using super() in constructor to correctly allow
diamond-shaped inheritance (through MRO). For instance: class A(object):
.... def __init__(self):
.... print "A.__init__"
.... super(A, self).__init__()
.... class B(A, list):
.... def __init__(self):
.... print "B.__init__"
.... super(B, self).__init__()
.... B.__mro__
(<class '__main__.B'>, <class '__main__.A'>, <type 'list'>, <type 'object'>) B()
B.__init__
A.__init__
[] class C(list, A):
.... def __init__(self):
.... print "C.__init__"
.... super(C, self).__init__()
.... C.__mro__
(<class '__main__.C'>, <type 'list'>, <class '__main__.A'>, <type 'object'>) C()
C.__init__
[]
It seems weird to me that I have to swap the order of bases to get the expected
behaviour. Is there a reason for this, or is it simply a bug that should be
fixed?
--
Giovanni Bajo 1 1036
Giovanni Bajo wrote: Hello,
I noticed that bultin types like list, set, dict, tuple don't seem to adhere to the convention of using super() in constructor to correctly allow diamond-shaped inheritance (through MRO). For instance: class A(object): ... def __init__(self): ... print "A.__init__" ... super(A, self).__init__() ... class B(A, list): ... def __init__(self): ... print "B.__init__" ... super(B, self).__init__() ... B.__mro__ (<class '__main__.B'>, <class '__main__.A'>, <type 'list'>, <type 'object'>) B() B.__init__ A.__init__ [] class C(list, A): ... def __init__(self): ... print "C.__init__" ... super(C, self).__init__() ... C.__mro__ (<class '__main__.C'>, <type 'list'>, <class '__main__.A'>, <type 'object'>) C()
C.__init__ [] It seems weird to me that I have to swap the order of bases to get the expected behaviour. Is there a reason for this, or is it simply a bug that should be fixed?
The documentation explicitly states that only one of the built-in types
can be used as a base class: they aren't desinged to be mixed with each
other.
regards
Steve
--
Meet the Python developers and your c.l.py favorites March 23-25
Come to PyCon DC 2005 http://www.pycon.org/
Steve Holden http://www.holdenweb.com/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Graham Banks |
last post by:
Does using multiple inheritance introduce any more performance overhead than
single inheritance?
|
by: Morgan Cheng |
last post by:
It seems no pattern defined by GoF takes advantage of multiple
inheritance. I am wondering if there is a situation where multiple
inheritance is a necessary solution.
When coding in C++, should...
|
by: km |
last post by:
Hi all,
In the following code why am i not able to access class A's object attribute - 'a' ? I wishto extent class D with all the attributes of its base classes. how do i do that ?
thanks in...
|
by: Matthew Louden |
last post by:
I want to know why C# doesnt support multiple inheritance? But why we can
inherit multiple interfaces instead? I know this is the rule, but I dont
understand why. Can anyone give me some concrete...
|
by: Mark |
last post by:
why doesn't .NET support multiple inheritance?
I think it's so silly!
Cheers,
Mark
|
by: Shawnk |
last post by:
Some Sr. colleges and I have had an on going discussion relative to when and
if
C# will ever support 'true' multiple inheritance.
Relevant to this, I wanted to query the C# community (the...
|
by: iKiLL |
last post by:
hi all,
I would like to be able to create an umbrella class for all my main global
sections but I would still like to keep them all in separate file something
like the below but I keep getting...
|
by: Adam Nielsen |
last post by:
Hi everyone,
I'm having some trouble getting the correct chain of constructors to be called when creating an object at the bottom of a hierarchy. Have a look at the code below - the inheritance...
|
by: Larry Smith |
last post by:
I just read a blurb in MSDN under the C++ "ref" keyword which states that:
"Under the CLR object model, only public single inheritance is supported".
Does this mean that no .NET class can ever...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
| |