Python 2.6, 3 abstract base class misunderstanding

Posted by Aaron on Stack Overflow See other posts from Stack Overflow or by Aaron
Published on 2010-05-19T00:46:08Z Indexed on 2010/05/19 0:50 UTC
Read the original article Hit count: 250

Filed under:
|

I'm not seeing what I expect when I use ABCMeta and abstractmethod.

This works fine in python3:

from abc import ABCMeta, abstractmethod
class Super(metaclass=ABCMeta):
@abstractmethod
def method(self):
    pass
a = Super()
TypeError: Can't instantiate abstract class Super ...

And in 2.6:

class Super():
__metaclass__ = ABCMeta
@abstractmethod
def method(self):
    pass
a = Super()
TypeError: Can't instantiate abstract class Super ...

They both also work fine (I get the expected exception) if I derive Super from object, in addition to ABCMeta.

They both "fail" (no exception raised) if I derive Super from list.

I want an abstract base class to be a list but abstract, and concrete in sub classes.

Am I doing it wrong, or should I not want this in python?

© Stack Overflow or respective owner

Related posts about python

Related posts about abstract-class