Issue 30463: Add slots to ABC convenience class (original) (raw)
We have slots with other ABC's, see http://bugs.python.org/issue11333 and http://bugs.python.org/issue21421.
There are no downsides to having empty slots on a non-instantiable class, but it does give the option of denying dict creation for subclassers.
The possibility of breaking is for someone using slots but relying on dict creation in a subclass - they will have to explicitly add "dict" to slots. Since we have added slots to other ABC's,
I will provide a PR soon on this. Diff should look like this (in Lib/abc.py):
class ABC(metaclass=ABCMeta): """Helper class that provides a standard way to create an ABC using inheritance. """
- pass
- slots = ()
(I also want to add a test for this, and ensure other ABC's also have this if they don't.)
I will note that this means with:
class BaseClass(ABC): pass
class MyDerivedClass(BaseClass):
def __init__(self, thing):
self.thing = thing
thing = MyDerivedClass()
thing now has both slots and, evidently, a dict. That's a bit weird and confusing.