Skip to content
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

Closed
durban mannequin opened this issue Feb 26, 2011 · 8 comments
Closed

Add empty __slots__ to collections.abc abstract base classes #55542

durban mannequin opened this issue Feb 26, 2011 · 8 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@durban
Copy link
Mannequin

durban mannequin commented Feb 26, 2011

BPO 11333
Nosy @gvanrossum, @rhettinger, @ncoghlan, @giampaolo, @merwok, @durban
Files
  • collections_abc_slots.diff: Patch (py3k branch)
  • 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:

    assignee = 'https://github.com/rhettinger'
    closed_at = <Date 2011-03-22.18:47:12.530>
    created_at = <Date 2011-02-26.12:24:33.617>
    labels = ['type-feature', 'library']
    title = 'Add empty __slots__ to collections.abc abstract base classes'
    updated_at = <Date 2011-03-22.18:47:12.529>
    user = 'https://github.com/durban'

    bugs.python.org fields:

    activity = <Date 2011-03-22.18:47:12.529>
    actor = 'rhettinger'
    assignee = 'rhettinger'
    closed = True
    closed_date = <Date 2011-03-22.18:47:12.530>
    closer = 'rhettinger'
    components = ['Library (Lib)']
    creation = <Date 2011-02-26.12:24:33.617>
    creator = 'daniel.urban'
    dependencies = []
    files = ['20910']
    hgrepos = []
    issue_num = 11333
    keywords = ['patch']
    message_count = 8.0
    messages = ['129534', '129570', '129578', '129625', '129641', '129661', '131763', '131764']
    nosy_count = 8.0
    nosy_names = ['gvanrossum', 'rhettinger', 'ncoghlan', 'giampaolo.rodola', 'stutzbach', 'eric.araujo', 'daniel.urban', 'python-dev']
    pr_nums = []
    priority = 'normal'
    resolution = 'accepted'
    stage = None
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue11333'
    versions = ['Python 3.3']

    @durban
    Copy link
    Mannequin Author

    durban mannequin commented Feb 26, 2011

    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.

    @durban durban mannequin added stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Feb 26, 2011
    @stutzbach
    Copy link
    Mannequin

    stutzbach mannequin commented Feb 26, 2011

    +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?

    @rhettinger
    Copy link
    Contributor

    Guido?

    @ncoghlan
    Copy link
    Contributor

    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.

    @gvanrossum
    Copy link
    Member

    I think the idea is reasonable. (I haven't checked the patch.)

    @gvanrossum gvanrossum assigned ncoghlan and unassigned gvanrossum Feb 27, 2011
    @rhettinger
    Copy link
    Contributor

    It looks like everyone is in favor of the change. I'll apply the patch after adding some comments and tests.

    @rhettinger rhettinger assigned rhettinger and unassigned ncoghlan Feb 27, 2011
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Mar 22, 2011

    New changeset d50a71994f51 by Raymond Hettinger in branch 'default':
    Issue bpo-11333: Add __slots__ to the collections ABCs.
    http://hg.python.org/cpython/rev/d50a71994f51

    @rhettinger
    Copy link
    Contributor

    Thanks Daniel.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants