Issue 9865: OrderedDict doesn't implement sizeof (original) (raw)

This issue has been migrated to GitHub: https://github.com/python/cpython/issues/54074

classification

Title: OrderedDict doesn't implement __sizeof__
Type: enhancement Stage: patch review
Components: Library (Lib) Versions: Python 3.2

process

Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: belopolsky, pitrou, rhettinger
Priority: low Keywords: patch

Created on 2010-09-15 21:12 by pitrou, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
od_size.diff rhettinger,2010-09-16 00:53 Patch for a __sizeof__ method.
Messages (8)
msg116481 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-09-15 21:12
Ordered dicts pretend to have the memory consumption as dicts: >>> import sys, collections >>> sys.getsizeof({}) 280 >>> sys.getsizeof(collections.OrderedDict()) 280
msg116484 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2010-09-15 21:28
I wonder if type metaclass can be taught to handle this in general for subclasses implemented in python.
msg116485 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-09-15 21:30
How do you want to "handle this in general"?
msg116487 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2010-09-15 21:37
> 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.
msg116488 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-09-15 21:39
> > 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).
msg116492 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2010-09-15 21:52
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.
msg116535 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-09-16 12:28
The patch looks good.
msg116993 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2010-09-20 22:32
See r84852
History
Date User Action Args
2022-04-11 14:57:06 admin set github: 54074
2010-09-20 22:32:53 rhettinger set status: open -> closedresolution: fixedmessages: +
2010-09-16 12:28:08 pitrou set messages: +
2010-09-16 00:53:31 rhettinger set files: + od_size.diffkeywords: + patchtype: behavior -> enhancementstage: patch review
2010-09-15 21:52:48 rhettinger set assignee: rhettingermessages: +
2010-09-15 21:39:48 pitrou set messages: +
2010-09-15 21:37:16 belopolsky set messages: +
2010-09-15 21:30:37 pitrou set messages: +
2010-09-15 21:28:58 belopolsky set nosy: + belopolskymessages: +
2010-09-15 21:12:37 pitrou create