Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #109891
| From | dieter <dieter@handshake.de> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Overriding methods inherited from a superclass with methods from a mixin |
| Date | 2016-06-13 09:13 +0200 |
| Message-ID | <mailman.30.1465802059.2288.python-list@python.org> (permalink) |
| References | <2a1088f1-3bdb-4b21-80b5-8cc640d3bceb@googlegroups.com> <87bn351ryl.fsf@handshake.de> |
alanqueiros@gmail.com writes:
> I'm trying to override methods inherited from a superclass by methods defined in a mixin class.
> Here's an sscce:
> https://bpaste.net/show/6c7d8d590658 (never expires)
>
> I've had problems finding the proper way to do that, since at first the base class wasn't to the right and I've assumed the correct order was from left to right.
The class' MRO ("Method Resolution Order") determines in which
order attributes are looked up.
Either, you must order your base classes in such a way that the MRO
controlled lookup finds the methods you want to be used or
you must explicitely put a definition for those methods in your
derived class (it may have the form "overridden_method = <BaseClass>.overridden_method").
The rules to determine the MRO are complex. The "inspect" module contains
a function ("get_mro") to show the MRO of a given class. Use it
to get your inheritance order right.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Overriding methods inherited from a superclass with methods from a mixin alanqueiros@gmail.com - 2016-06-12 20:55 -0700
Re: Overriding methods inherited from a superclass with methods from a mixin dieter <dieter@handshake.de> - 2016-06-13 09:13 +0200
Re: Overriding methods inherited from a superclass with methods from a mixin Peter Otten <__peter__@web.de> - 2016-06-13 09:59 +0200
Re: Overriding methods inherited from a superclass with methods from a mixin Ian Kelly <ian.g.kelly@gmail.com> - 2016-06-13 07:17 -0600
Re: Overriding methods inherited from a superclass with methods from a mixin Michael Selik <michael.selik@gmail.com> - 2016-06-13 17:32 +0000
Re: Overriding methods inherited from a superclass with methods from a mixin alanqueiros@gmail.com - 2016-06-13 11:42 -0700
Re: Overriding methods inherited from a superclass with methods from a mixin Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2016-06-14 10:28 +1200
Re: Overriding methods inherited from a superclass with methods from a mixin Michael Selik <michael.selik@gmail.com> - 2016-06-13 22:50 +0000
Re: Overriding methods inherited from a superclass with methods from a mixin alanqueiros@gmail.com - 2016-06-13 16:44 -0700
Re: Overriding methods inherited from a superclass with methods from a mixin Michael Selik <michael.selik@gmail.com> - 2016-06-14 00:13 +0000
csiph-web