Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Gaurav Munjal
Gaurav Munjal
398 Points

Multiple Inheritance Conceptual Question

In the video, at around 5 min, it says that "sneaky" and "agile" arguments may not be recognized by certain python versions because certain properties do not travel all the way up to top parent class.

  • Question 1 - Why ?
  • Question 2 - Why do have super().__init__ in sneaky and agile classes if the only parent class they have is Object ?
  • Question 3 - What benefit do we get in making character class as final class ?

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,423 Points

Good questions:

Question 1 - Why ?

I could not find the specific case where the version of Python would matter in the MRO unless you go back to an very old version of Python 2, So, I would say the comment is moot if you're using a modern 2.7+, 3.5+ version of Python.

Please note that with Character as the first class in the inheritance list and the Character.__init__ does not have a super call, neither Agile.__init__ or Sneaky.__init__ would be executed. The setting of the self.sneaky attribute is happening in the Character loop using setattr.

Question 2 - Why do have super().__init__ in sneaky and agile classes if the only parent class they have is Object ?

Any super call become effectives when there are multiple parent classes are inherited from. A super within` a parent class says "if I don't have a parent, then run this same method contained *in the next parent in the inherited list". The Agile.super calls Sneaky. The Sneaky.super calls Character.

Question 3 - What benefit do we get in making character class as final class ?

By making Character the final class, it allows that class to be the default structure of the defined class Thief. Any supplemental features added to augment the Thief class can then be added before Character. In terms of design, Character is the "base class" of Thief and the classes Agile and Sneaky can be thought of as "add in features".

Post back if you wish more clarification. Good luck!!