A subclass that subclasses ABC and OrderedDict does not act as a true abstract class:
>>> from abc import ABC, abstractmethod
>>> from collections import OrderedDict
>>> class AbstractOrderedDict(OrderedDict, ABC):
... @abstractmethod
... def abstract_method(self):
... pass
...
>>> AbstractOrderedDict()
AbstractOrderedDict()
One would expect an instantiation of AbstractOrderedDict to fail, right?
Further experimentation showed that subclassing object
and ABC
raises a TypeError on instantiation, as expected (obviously), but subclassing any other basic class (dict, int, list, etc.) does not (behaves as above).
Questions:
- Why does it behave this way?
- Is it a bad idea, in theory, to make an abstract subclass of OrderedDict (or others)?
- Why?
- Alternatives?