Issue11333
Created on 2011-02-26 12:24 by daniel.urban, last changed 2022-04-11 14:57 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| collections_abc_slots.diff | daniel.urban, 2011-02-26 12:24 | Patch (py3k branch) | review | |
| Messages (8) | |||
|---|---|---|---|
| msg129534 - (view) | Author: Daniel Urban (daniel.urban) * ![]() |
Date: 2011-02-26 12:24 | |
Currently instances of classes which inherit an ABC in collections.abc will have a __dict__. This can be a problem for example a tree-like data structure. It would make sense to inherit for example MutableMapping, but that would possibly mean, that every node in the tree would have a __dict__, which is probably a waste of memory. A workaround for this problem is not inheriting the ABC, and using ABCMeta.register (and optionally adding the mixin methods explicitly), but this feels like a hack. The attached patch adds an empty __slots__ to the ABCs in collections.abc. I excluded the mapping views (MappingView, KeysView, ItemsView and ValuesView), because they can't have an empty __slots__, and I think using a nonempty __slots__ possibly can cause problems in some cases with multiple inheritance. |
|||
| msg129570 - (view) | Author: Daniel Stutzbach (stutzbach) ![]() |
Date: 2011-02-26 16:31 | |
+1. I've bumped into exactly this problem (https://github.com/DanielStutzbach/blist/issues/closed#issue/29) I'm not intimately familiar with how __slots__ works. Are there any drawbacks to adding an empty __slots__ to the ABCs? |
|||
| msg129578 - (view) | Author: Raymond Hettinger (rhettinger) * ![]() |
Date: 2011-02-26 17:31 | |
Guido? |
|||
| msg129625 - (view) | Author: Alyssa Coghlan (ncoghlan) * ![]() |
Date: 2011-02-27 13:57 | |
I like the idea, and it seems to work as expected (i.e. an empty __slots__ doesn't conflict with inheritance from a C defined type or a type with non-empty __slots__). However, __slots__ is one of the sections of the type machinery I'm least familiar with, so hopefully Guido will weigh in. |
|||
| msg129641 - (view) | Author: Guido van Rossum (gvanrossum) * ![]() |
Date: 2011-02-27 17:57 | |
I think the idea is reasonable. (I haven't checked the patch.) |
|||
| msg129661 - (view) | Author: Raymond Hettinger (rhettinger) * ![]() |
Date: 2011-02-27 22:00 | |
It looks like everyone is in favor of the change. I'll apply the patch after adding some comments and tests. |
|||
| msg131763 - (view) | Author: Roundup Robot (python-dev) ![]() |
Date: 2011-03-22 18:46 | |
New changeset d50a71994f51 by Raymond Hettinger in branch 'default': Issue #11333: Add __slots__ to the collections ABCs. http://hg.python.org/cpython/rev/d50a71994f51 |
|||
| msg131764 - (view) | Author: Raymond Hettinger (rhettinger) * ![]() |
Date: 2011-03-22 18:47 | |
Thanks Daniel. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:57:13 | admin | set | github: 55542 |
| 2011-03-22 18:47:12 | rhettinger | set | status: open -> closed messages:
+ msg131764 |
| 2011-03-22 18:46:35 | python-dev | set | nosy:
+ python-dev messages: + msg131763 |
| 2011-02-27 22:58:43 | rhettinger | set | files:
- annotations_workaround.py nosy: gvanrossum, rhettinger, ncoghlan, giampaolo.rodola, stutzbach, eric.araujo, daniel.urban |
| 2011-02-27 22:58:34 | rhettinger | set | nosy:
gvanrossum, rhettinger, ncoghlan, giampaolo.rodola, stutzbach, eric.araujo, daniel.urban messages: - msg129664 |
| 2011-02-27 22:58:10 | rhettinger | set | files:
+ annotations_workaround.py nosy: gvanrossum, rhettinger, ncoghlan, giampaolo.rodola, stutzbach, eric.araujo, daniel.urban messages: + msg129664 |
| 2011-02-27 22:00:06 | rhettinger | set | assignee: ncoghlan -> rhettinger messages: + msg129661 nosy: gvanrossum, rhettinger, ncoghlan, giampaolo.rodola, stutzbach, eric.araujo, daniel.urban |
| 2011-02-27 17:57:01 | gvanrossum | set | assignee: gvanrossum -> ncoghlan messages: + msg129641 nosy: gvanrossum, rhettinger, ncoghlan, giampaolo.rodola, stutzbach, eric.araujo, daniel.urban |
| 2011-02-27 13:57:06 | ncoghlan | set | nosy:
+ ncoghlan messages: + msg129625 |
| 2011-02-26 17:31:49 | rhettinger | set | assignee: gvanrossum messages:
+ msg129578 |
| 2011-02-26 16:36:32 | eric.araujo | set | nosy:
+ eric.araujo |
| 2011-02-26 16:31:07 | stutzbach | set | nosy:
rhettinger, giampaolo.rodola, stutzbach, daniel.urban messages: + msg129570 |
| 2011-02-26 13:58:20 | giampaolo.rodola | set | nosy:
+ giampaolo.rodola |
| 2011-02-26 12:24:33 | daniel.urban | create | |

