Why Isn't Multiple Inheritance Automatic in Python?

Discussion in 'Python' started by Nick M. Daly, Dec 17, 2012.

  1. Nick M. Daly

    Nick M. Daly Guest

    If you're short on time, the subject's all you need to read. It seems
    like it would always be the right thing to do, when the sub-class
    specifically requests it.

    It's very unlikely that multiple inheritance would go horribly wrong, as
    long as classes adopt class-specific argument naming conventions.
    However, ever since bug 1683368 [0] was fixed, it's now impossible to
    cleanly create arbitrary inheritance trees. The only reason I can't
    just take anybody's code and plop it into my inheritance tree is because
    Python demands that each class specifically opts in to MI though
    mechanisms like the following:

    1: class Foo(object):
    2: def __init__(self, foo_bar, *args, **kwargs):
    3: if Foo.__mro__[1] != object:
    4: super().__init__(*args, **kwargs)
    5:
    6: self.bar = foo_bar

    Lines 3 and 4 are required because Foo might fall at the beginning or
    the middle of in the inheritance tree: we can't know ahead of time.

    >From my perspective, it'd be lovely if init methods implicitly accepted

    *args and **kwargs while implicitly sending them off to the next class
    in the MRO as the first call. This would make the previous example
    semantically equivalent to:

    1: class Foo(object):
    2: def __init__(self, foo_bar):
    3: self.bar = foo_bar

    Granted, that's probably too excessive and implicit for most folks to be
    comfortable with, even though that's obviously the behavior a user
    intends when they write code like:

    1: class Baz(Foo, Bar):
    2: def __init__(self):
    3: super().__init__(foo_bar=1, bar_quote="Give me another!")

    Fundamentally, I don't care if Foo or Bar explicitly handle being
    composed into the inheritance tree. They can be composed correctly
    (they can do what the user is asking) in most obvious and simple cases,
    and it'd be fine by me even if we threw errors in complex situations
    (like overlapping argument names in init methods).

    So, would it be a good idea to:

    1. Undo the fix to bug 1683368, making multiple inheritance easier?

    2. Make MI implicit, when subclasses try to use it?

    Thanks for your time,
    Nick

    0: http://bugs.python.org/issue1683368
    Nick M. Daly, Dec 17, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Vla
    Replies:
    30
    Views:
    1,014
    Jerry Coffin
    Jan 25, 2005
  2. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    862
    Mark Rae
    Dec 21, 2006
  3. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,762
    Smokey Grindel
    Dec 2, 2006
  4. Ian Kelly
    Replies:
    0
    Views:
    138
    Ian Kelly
    Dec 17, 2012
  5. Terry Reedy
    Replies:
    0
    Views:
    95
    Terry Reedy
    Dec 17, 2012
Loading...

Share This Page