[Python-Dev] One-line abstractmethod function?
Guido van Rossum
guido at python.org
Fri Dec 6 03:57:21 CET 2013
On Thu, Dec 5, 2013 at 6:08 PM, Allen Li <cyberdupo56 at gmail.com> wrote:
> On Thu, Dec 05, 2013 at 01:33:00PM -0800, Guido van Rossum wrote:
>> > The only two alternatives are doing nothing/pass/return
>> > None or having actual code in the method.
>> > The former is only useful to silently ignore blind super() calling, the
>> > latter you would define and decorate the method normally.
>> Actually if you want to support multiple inheritance of your ABC, your
>> abstract methods *must* be no-ops (or have some kind of default
>> behavior that can always be done last).
> I must respectfully disagree with this. If your ABCs aren't meant to be
> in the MRO, then you should be @registering them as virtual classes and
> not inheriting them.
Registering is meant to be a method of last resort; it is implemented
for cases where an ABC is introduced after implementations already
exist (IOW, formalizing duck typing). When the ABC *is* actually used
as a base class, when the standard M.I. patterns are used, the
abstract methods must be no-ops, because they will be called (last).
> The trick with Python multiple inheritance and super() (from personal
> experience) is to not think of it as multiple inheritance (a tree with
> cycles), but as building the MRO (linear, the same as single
I'm not sure I understand -- or maybe I disagree. "A tree with cycles"
seems a really poor way to describe what is usually referred to as a
"diamond inheritance diagram". The right patterns require that you
design your class to be unaware of the exact MRO. But we're getting
off-topic. You should probably read one of the standard tutorials on
the topic to refresh your use of the terminology.
--Guido van Rossum (python.org/~guido)
More information about the Python-Dev