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

OrderedDict doesn't implement __sizeof__ #54074

Closed
pitrou opened this issue Sep 15, 2010 · 8 comments
Closed

OrderedDict doesn't implement __sizeof__ #54074

pitrou opened this issue Sep 15, 2010 · 8 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@pitrou
Copy link
Member

pitrou commented Sep 15, 2010

BPO 9865
Nosy @rhettinger, @abalkin, @pitrou
Files
  • od_size.diff: Patch for a sizeof method.
  • 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 2010-09-20.22:32:53.284>
    created_at = <Date 2010-09-15.21:12:37.603>
    labels = ['type-feature', 'library']
    title = "OrderedDict doesn't implement __sizeof__"
    updated_at = <Date 2010-09-20.22:32:53.283>
    user = 'https://github.com/pitrou'

    bugs.python.org fields:

    activity = <Date 2010-09-20.22:32:53.283>
    actor = 'rhettinger'
    assignee = 'rhettinger'
    closed = True
    closed_date = <Date 2010-09-20.22:32:53.284>
    closer = 'rhettinger'
    components = ['Library (Lib)']
    creation = <Date 2010-09-15.21:12:37.603>
    creator = 'pitrou'
    dependencies = []
    files = ['18896']
    hgrepos = []
    issue_num = 9865
    keywords = ['patch']
    message_count = 8.0
    messages = ['116481', '116484', '116485', '116487', '116488', '116492', '116535', '116993']
    nosy_count = 3.0
    nosy_names = ['rhettinger', 'belopolsky', 'pitrou']
    pr_nums = []
    priority = 'low'
    resolution = 'fixed'
    stage = 'patch review'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue9865'
    versions = ['Python 3.2']

    @pitrou
    Copy link
    Member Author

    pitrou commented Sep 15, 2010

    Ordered dicts pretend to have the memory consumption as dicts:

    >>> import sys, collections
    >>> sys.getsizeof({})
    280
    >>> sys.getsizeof(collections.OrderedDict())
    280

    @pitrou pitrou added type-bug An unexpected behavior, bug, or error stdlib Python modules in the Lib dir labels Sep 15, 2010
    @abalkin
    Copy link
    Member

    abalkin commented Sep 15, 2010

    I wonder if type metaclass can be taught to handle this in general for subclasses implemented in python.

    @pitrou
    Copy link
    Member Author

    pitrou commented Sep 15, 2010

    How do you want to "handle this in general"?

    @abalkin
    Copy link
    Member

    abalkin commented Sep 15, 2010

    How do you want to "handle this in general"?

    Possibly by adding up __sizeof__'s of base and __dict__ in a generated function? With a special handling of slots ...

    May prove to be too complicated to be worth the effort.

    @pitrou
    Copy link
    Member Author

    pitrou commented Sep 15, 2010

    > How do you want to "handle this in general"?

    Possibly by adding up __sizeof__'s of base and __dict__ in a generated
    function? With a special handling of slots ...

    I agree that in the general case this would be better, but for
    OrderedDict it would still fail to give the right value (OrderedDict
    also needs to take into account its internal node objects).

    @rhettinger
    Copy link
    Contributor

    I have a hard time caring about this. The main value of sys.getsizeof()
    is to enable developers to determine the internal sizes of basic objects on a given build. IIRC, there was no intention for this to become a requirement for pure python classes.

    @rhettinger rhettinger self-assigned this Sep 15, 2010
    @rhettinger rhettinger added type-feature A feature request or enhancement and removed type-bug An unexpected behavior, bug, or error labels Sep 16, 2010
    @pitrou
    Copy link
    Member Author

    pitrou commented Sep 16, 2010

    The patch looks good.

    @rhettinger
    Copy link
    Contributor

    See r84852

    @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