New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add empty __slots__ to collections.abc abstract base classes #55542
Comments
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. |
+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? |
Guido? |
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. |
I think the idea is reasonable. (I haven't checked the patch.) |
It looks like everyone is in favor of the change. I'll apply the patch after adding some comments and tests. |
New changeset d50a71994f51 by Raymond Hettinger in branch 'default': |
Thanks Daniel. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: