[New-bugs-announce] [issue38262] Mixins - super calls in bases of multiple-inheritance with different parameters

Arno-Can Uestuensoez report at bugs.python.org
Tue Sep 24 06:11:33 EDT 2019


New submission from Arno-Can Uestuensoez <acue.opensource at gmail.com>:

The attached examples evaluate inheritance by mixins with different
arameters and in different orders.

The 'super()' call propagates the call resolution by definition
to the next level, and cares about multiple inheritance as well
as mixins. Where mixins are the superior case as they represent multiple inheritance in any case due to the common top class 'object'.
So far perfect.

The oddity I came around is the simple case of mixins with different
parameters, where both are derived from 'object'. It is obvious, that such a class has to comply to the parents call interface - here object - when to be used standalone. BUT when I ignore this and set intentionally a parameter - for test-purposes of mixins only - the resolution algorithm seems to normalize both for the final call without parameters -  as soon as one of the mixins is a non-parameter call. This is independent from the inheritance order for the derived class.

I expect for the rightmost of the inherited classes to pass the parameters literally.

When both classes have parameters, the parameter is passed to 'object' and correctly raises an exception.

#----------------------------------------------------------

[acue at lap001 mixin-order-with-different-params]$ ./call.sh 

************************

different parameters for mixin classes at diffeent positions

  0: super() method signature has no param
  1: super() method signature has param

final top-class is 'object()' which does not know the 
parameter - here 'propagate'

************************

#---------------
#
# CALL: mixin_C_is_A1B0.py
#
B:C
A:C
C:C

#---------------
#
# CALL: mixin_C_is_A1B1.py
#
Traceback (most recent call last):
  File "mixin_C_is_A1B1.py", line 24, in <module>
    c=C(True)        
  File "mixin_C_is_A1B1.py", line 20, in __init__
    super(C, self).__init__(propagate)
  File "mixin_C_is_A1B1.py", line 4, in __init__
    super(A, self).__init__(propagate)
  File "mixin_C_is_A1B1.py", line 12, in __init__
    super(B, self).__init__(propagate)
TypeError: object.__init__() takes no parameters

#---------------
#
# CALL: mixin_C_is_B0A1.py
#
A:C
B:C
C:C

#---------------
#
# CALL: mixin_C_is_B1A1.py
#
Traceback (most recent call last):
  File "mixin_C_is_B1A1.py", line 25, in <module>
    c=C(True)        
  File "mixin_C_is_B1A1.py", line 20, in __init__
    super(C, self).__init__(propagate)
  File "mixin_C_is_B1A1.py", line 12, in __init__
    super(B, self).__init__(propagate)
  File "mixin_C_is_B1A1.py", line 4, in __init__
    super(A, self).__init__(propagate)
TypeError: object.__init__() takes no parameters

[acue at lap001 mixin-order-with-different-params]$ 


#----------------------------------------------


Is this intentional?

If so, what is the explanation? - Because it potentially hides bugs for later debugging...

----------
files: tests.tar.gz
messages: 353062
nosy: acue
priority: normal
severity: normal
status: open
title: Mixins - super calls in bases of multiple-inheritance with different parameters
type: compile error
versions: Python 2.7, Python 3.6
Added file: https://bugs.python.org/file48621/tests.tar.gz

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue38262>
_______________________________________


More information about the New-bugs-announce mailing list