This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Add __slots__ to ABC convenience class
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Aaron Hall, cjw296, levkivskyi, rhettinger, serhiy.storchaka
Priority: normal Keywords:

Created on 2017-05-24 20:41 by Aaron Hall, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 1822 merged Aaron Hall, 2017-05-26 04:45
Messages (4)
msg294389 - (view) Author: Aaron Hall (Aaron Hall) * Date: 2017-05-24 20:41
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.)
msg294420 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2017-05-25 00:46
This seems reasonable.
msg295297 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-06-06 19:34
New changeset ff48739ed0a3f366c4d56d3c86a37cbdeec600de by Serhiy Storchaka (Aaron Hall, MBA) in branch 'master':
bpo-30463: Add an empty __slots__ to abc.ABC.
https://github.com/python/cpython/commit/ff48739ed0a3f366c4d56d3c86a37cbdeec600de
msg356740 - (view) Author: Chris Withers (cjw296) * (Python committer) Date: 2019-11-16 01:14
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.
History
Date User Action Args
2022-04-11 14:58:46adminsetgithub: 74648
2019-11-16 01:14:18cjw296setnosy: + cjw296
messages: + msg356740
2017-06-06 19:38:51serhiy.storchakasetstatus: open -> closed
versions: + Python 3.7
resolution: fixed
components: + Library (Lib)
type: enhancement
stage: resolved
2017-06-06 19:34:59serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg295297
2017-05-26 20:24:30levkivskyisetnosy: + levkivskyi
2017-05-26 04:45:34Aaron Hallsetpull_requests: + pull_request1908
2017-05-25 00:46:51rhettingersetnosy: + rhettinger
messages: + msg294420
2017-05-24 20:41:17Aaron Hallcreate