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 __slots__ to ABC convenience class #74648

Closed
aaronchall mannequin opened this issue May 24, 2017 · 4 comments
Closed

Add __slots__ to ABC convenience class #74648

aaronchall mannequin opened this issue May 24, 2017 · 4 comments
Labels
3.7 (EOL) end of life stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@aaronchall
Copy link
Mannequin

aaronchall mannequin commented May 24, 2017

BPO 30463
Nosy @rhettinger, @cjw296, @serhiy-storchaka, @ilevkivskyi, @aaronchall
PRs
  • bpo-30463 ABC has empty __slots__, with unittest #1822
  • 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 = None
    closed_at = <Date 2017-06-06.19:38:51.124>
    created_at = <Date 2017-05-24.20:41:17.931>
    labels = ['3.7', 'type-feature', 'library']
    title = 'Add __slots__ to ABC convenience class'
    updated_at = <Date 2019-11-16.01:14:18.818>
    user = 'https://github.com/aaronchall'

    bugs.python.org fields:

    activity = <Date 2019-11-16.01:14:18.818>
    actor = 'cjw296'
    assignee = 'none'
    closed = True
    closed_date = <Date 2017-06-06.19:38:51.124>
    closer = 'serhiy.storchaka'
    components = ['Library (Lib)']
    creation = <Date 2017-05-24.20:41:17.931>
    creator = 'Aaron Hall'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 30463
    keywords = []
    message_count = 4.0
    messages = ['294389', '294420', '295297', '356740']
    nosy_count = 5.0
    nosy_names = ['rhettinger', 'cjw296', 'serhiy.storchaka', 'levkivskyi', 'Aaron Hall']
    pr_nums = ['1822']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue30463'
    versions = ['Python 3.7']

    @aaronchall
    Copy link
    Mannequin Author

    aaronchall mannequin commented May 24, 2017

    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.)

    @rhettinger
    Copy link
    Contributor

    This seems reasonable.

    @serhiy-storchaka
    Copy link
    Member

    New changeset ff48739 by Serhiy Storchaka (Aaron Hall, MBA) in branch 'master':
    bpo-30463: Add an empty __slots__ to abc.ABC.
    ff48739

    @serhiy-storchaka serhiy-storchaka added 3.7 (EOL) end of life stdlib Python modules in the Lib dir labels Jun 6, 2017
    @serhiy-storchaka serhiy-storchaka added the type-feature A feature request or enhancement label Jun 6, 2017
    @cjw296
    Copy link
    Contributor

    cjw296 commented Nov 16, 2019

    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.

    @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
    3.7 (EOL) end of life 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