You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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=Noneclosed_at=<Date2020-03-22.22:33:40.085>created_at=<Date2012-07-23.19:54:41.953>labels= ['easy', 'type-feature', 'invalid', 'docs']
title='__sizeof__ is not documented'updated_at=<Date2020-03-22.22:33:40.084>user='https://github.com/serhiy-storchaka'
It is part of runtime services and is mentioned in the documentation for 'sys.getsizeof' [1]:
"""
getsizeof() calls the object’s __sizeof__ method and adds an additional garbage collector overhead if the object is managed by the garbage collector.
"""
bpo-2898 smells like an implementation detail to me. Also, sys.getsizeof() isn't necessarily authoritative here, since the sys module is full of all sorts of implementation details.
I'm not saying __sizeof__ shouldn't be made an official part of the language, but we should be careful before we effectively etch something in stone for all Python implementations. It may be worth getting feedback from python-dev, particularly from the major Python implementers.
Also, sys.getsizeof() hasn't proved to be very useful (I never see anyone use it or see it in production code). Worse, it doesn't even make sense in the case of shared-key dictionaries and whatnot. Accordingly, there is little reason to make this more public than it already is. I would be happy to see it written-off as an implementation detail.
sys.getsizeof() is not for production code, it's for experimenting and getting information at the command prompt. It's quite useful when you know its limitations.
I'd argue that implementing __sizeof__ for user types doesn't make much sense (except C extension types, which are CPython-specific).
loewis commented on Jul 29, 2012
loewismannequin
Mannequin
More actions
rhettinger: users frequently need sys.getsizeof. See, for example,
In what cases, do you think, it generates meaningless results? I find the results for the shared-keys dictionary quite meaningful and natural.
sys.getsizeof is certainly CPython-specific. However, __sizeof__ is not just an implementation detail of sys.getsizeof, just as __len__ is not an implementation detail of len(). Authors of extension types are supposed to implement it if object.__sizeof__ is incorrect.
sys.getsizeof is certainly CPython-specific. However, __sizeof__ is not
just an implementation detail of sys.getsizeof, just as __len__ is not an
implementation detail of len(). Authors of extension types are supposed to
implement it if object.__sizeof__ is incorrect.
I think there is one difference between __len__ and __sizeof__. __sizeof__
should be overloaded only for C-implemented classes. IMHO, it is a part of C
API.
loewis commented on Jul 29, 2012
loewismannequin
Mannequin
More actions
I think there is one difference between __len__ and __sizeof__. __sizeof__
should be overloaded only for C-implemented classes. IMHO, it is a part of C
API.
That is a reasonable point. So documenting it along with the type slots
might be best.
Activity
serhiy-storchaka commentedon Jul 23, 2012
__sizeof__ is not mentioned on page Doc/reference/datamodel.rst together with other special methods. There is no __sizeof__ in index.
[-]__sizeof__ is not documeneted[/-][+]__sizeof__ is not documented[/+]jcea commentedon Jul 23, 2012
Could you possibly write a patch for 2.7, 3.2 and 3.3?
serhiy-storchaka commentedon Jul 24, 2012
No, not for documentation.
ericsnowcurrently commentedon Jul 24, 2012
is __sizeof__ part of the language or just an implementation detail?
serhiy-storchaka commentedon Jul 24, 2012
See bpo-2898.
meadori commentedon Jul 24, 2012
It is part of runtime services and is mentioned in the documentation for 'sys.getsizeof' [1]:
"""
getsizeof() calls the object’s __sizeof__ method and adds an additional garbage collector overhead if the object is managed by the garbage collector.
"""
[1] http://docs.python.org/library/sys.html?highlight=__sizeof__#sys.getsizeof.
serhiy-storchaka commentedon Jul 24, 2012
Yes, but it is not mentioned in the index.
ericsnowcurrently commentedon Jul 25, 2012
bpo-2898 smells like an implementation detail to me. Also, sys.getsizeof() isn't necessarily authoritative here, since the sys module is full of all sorts of implementation details.
I'm not saying __sizeof__ shouldn't be made an official part of the language, but we should be careful before we effectively etch something in stone for all Python implementations. It may be worth getting feedback from python-dev, particularly from the major Python implementers.
rhettinger commentedon Jul 25, 2012
This may be CPython specific.
Also, sys.getsizeof() hasn't proved to be very useful (I never see anyone use it or see it in production code). Worse, it doesn't even make sense in the case of shared-key dictionaries and whatnot. Accordingly, there is little reason to make this more public than it already is. I would be happy to see it written-off as an implementation detail.
pitrou commentedon Jul 25, 2012
sys.getsizeof() is not for production code, it's for experimenting and getting information at the command prompt. It's quite useful when you know its limitations.
I'd argue that implementing __sizeof__ for user types doesn't make much sense (except C extension types, which are CPython-specific).
loewis commentedon Jul 29, 2012
rhettinger: users frequently need sys.getsizeof. See, for example,
http://stackoverflow.com/questions/1331471/in-memory-size-of-python-stucture
http://stackoverflow.com/questions/449560/how-do-i-determine-the-size-of-an-object-in-python
http://stackoverflow.com/questions/2117255/python-deep-getsizeof-list-with-contents
http://stackoverflow.com/questions/11301295/measure-object-size-accurately-in-python-sys-getsizeof-not-functioning
[and so on]
In what cases, do you think, it generates meaningless results? I find the results for the shared-keys dictionary quite meaningful and natural.
sys.getsizeof is certainly CPython-specific. However, __sizeof__ is not just an implementation detail of sys.getsizeof, just as __len__ is not an implementation detail of len(). Authors of extension types are supposed to implement it if object.__sizeof__ is incorrect.
serhiy-storchaka commentedon Jul 29, 2012
I think there is one difference between __len__ and __sizeof__. __sizeof__
should be overloaded only for C-implemented classes. IMHO, it is a part of C
API.
loewis commentedon Jul 29, 2012
That is a reasonable point. So documenting it along with the type slots
might be best.
idomic commentedon Sep 22, 2019
I can add those changes if someone didn't take it already?
Ido
rhettinger commentedon Mar 22, 2020
I think we've decided that this is an implementation specific detail.