Skip to content

__sizeof__ is not documented #59641

Closed
Closed

Description

@serhiy-storchaka
BPO 15436
Nosy @loewis, @rhettinger, @jcea, @pitrou, @asvetlov, @meadori, @ericsnowcurrently, @serhiy-storchaka

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 2020-03-22.22:33:40.085>
created_at = <Date 2012-07-23.19:54:41.953>
labels = ['easy', 'type-feature', 'invalid', 'docs']
title = '__sizeof__ is not documented'
updated_at = <Date 2020-03-22.22:33:40.084>
user = 'https://github.com/serhiy-storchaka'

bugs.python.org fields:

activity = <Date 2020-03-22.22:33:40.084>
actor = 'rhettinger'
assignee = 'docs@python'
closed = True
closed_date = <Date 2020-03-22.22:33:40.085>
closer = 'rhettinger'
components = ['Documentation']
creation = <Date 2012-07-23.19:54:41.953>
creator = 'serhiy.storchaka'
dependencies = []
files = []
hgrepos = []
issue_num = 15436
keywords = ['easy']
message_count = 15.0
messages = ['166245', '166253', '166263', '166265', '166266', '166304', '166309', '166353', '166438', '166439', '166782', '166789', '166796', '352974', '364828']
nosy_count = 14.0
nosy_names = ['loewis', 'rhettinger', 'jcea', 'pitrou', 'cvrebert', 'asvetlov', 'meador.inge', 'docs@python', 'eric.snow', 'aliles', 'serhiy.storchaka', 'mjdorma', 'sptonkin', 'Philip Dye']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue15436'
versions = ['Python 2.7', 'Python 3.2', 'Python 3.3', 'Python 3.4']

Activity

  1. serhiy-storchaka commented on Jul 23, 2012

    @serhiy-storchaka
    MemberAuthor

    __sizeof__ is not mentioned on page Doc/reference/datamodel.rst together with other special methods. There is no __sizeof__ in index.

  2. changed the title [-]__sizeof__ is not documeneted[/-] [+]__sizeof__ is not documented[/+] on Jul 23, 2012
  3. jcea commented on Jul 23, 2012

    @jcea
    Member

    Could you possibly write a patch for 2.7, 3.2 and 3.3?

  4. serhiy-storchaka commented on Jul 24, 2012

    @serhiy-storchaka
    MemberAuthor

    Could you possibly write a patch for 2.7, 3.2 and 3.3?

    No, not for documentation.

  5. ericsnowcurrently commented on Jul 24, 2012

    @ericsnowcurrently
    Member

    is __sizeof__ part of the language or just an implementation detail?

  6. serhiy-storchaka commented on Jul 24, 2012

    @serhiy-storchaka
    MemberAuthor
  7. meadori commented on Jul 24, 2012

    @meadori
    Member

    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.

  8. serhiy-storchaka commented on Jul 24, 2012

    @serhiy-storchaka
    MemberAuthor

    It is part of runtime services and is mentioned in the documentation for
    'sys.getsizeof' [1]:

    Yes, but it is not mentioned in the index.

  9. ericsnowcurrently commented on Jul 25, 2012

    @ericsnowcurrently
    Member

    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.

  10. rhettinger commented on Jul 25, 2012

    @rhettinger
    Contributor

    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.

  11. pitrou commented on Jul 25, 2012

    @pitrou
    Member

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

  12. loewis commented on Jul 29, 2012

    loewismannequin
    Mannequin

    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.

  13. serhiy-storchaka commented on Jul 29, 2012

    @serhiy-storchaka
    MemberAuthor

    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.

  14. loewis commented on Jul 29, 2012

    loewismannequin
    Mannequin

    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.

  15. idomic commented on Sep 22, 2019

    idomicmannequin
    Mannequin

    I can add those changes if someone didn't take it already?

    Ido

  16. rhettinger commented on Mar 22, 2020

    @rhettinger
    Contributor

    I can add those changes if someone didn't take it already?

    I think we've decided that this is an implementation specific detail.

  17. transferred this issue fromon Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc direasytype-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions