[Tutor] Modify inherited methods

Emile van Sebille emile at fenx.com
Wed Apr 28 17:56:30 CEST 2010


On 4/28/2010 3:20 AM Walter Wefft said...
> spir ☣ wrote:
>> On Wed, 28 Apr 2010 07:53:06 +0100
>> Walter Wefft <walterwefft at googlemail.com> wrote:
<snip>
>> ===============================
>> class MyDict0(dict):
>> pass
>> class MyDict1(dict):
>> def __init__(self, *args, **kw):
>> pass
>> class MyDict2(dict):
>> def __init__(self, *args, **kw):
>> dict.__init__(self, *args, **kw)
>> ===============================
>>
>> d0 = MyDict0(a=1) ; d1 = MyDict1(a=1) ; d2 = MyDict2(a=1)
>> print d0,d1,d2 # ==> {'a': 1} {} {'a': 1}
>>
>
> You reiterate my point. To say that dict.__init__ can be omitted in a
> subclass's __init__ with no effect, is not a correct statement.
>

It wasn't the omitted case that exhibits the difference.  When 
sub-classing, any methods omitted defer to the parent's version so the 
init from the dict parent happened.

Emile



More information about the Tutor mailing list