On Tue, Mar 27, 2018 at 8:47 AM, Ian Kelly <ian.g.ke...@gmail.com> wrote:
> On Tue, Mar 27, 2018 at 12:21 AM, Gregory Ewing
> <greg.ew...@canterbury.ac.nz> wrote:
>> The trouble is, those conditions don't always hold.
>> Often when overriding a method, you want to do something
>> *instead* of what the base method does.
>
> As noted above, unless the method or class is abstract then this
> violates LSP. If the method is abstract and does nothing, then just
> call it. If the method is abstract and raises an exception, then
> that's a little more tricky. Ideally, don't write abstract methods
> that raise NotImplementedError unless they're not intended to be used
> with multiple inheritance.
>
> If you really need to though, you can solve this by creating a guard
> class that implements the method and does nothing, ending the super
> call chain. Then just make sure that at least one subclass in the
> multiple inheritance diagram inherits from the guard class rather than
> the original class.

Er, this should say "make sure that every subclass ... inherits from
the guard class ..." since we want to make sure that nothing else ends
up between the guard class and the original class.
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to