python / python/cpython

Clarify the diffrence between object.__sizeof__() and sys.getsizeof() in short documentation/help output

Aberta
#146,086 0 comentários 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

docs
Linguagem predominante
Python
Estrelas
77.2k
Forks
36k
Métricas de merge de PRs
Métricas de PR pendentes

Descrição

Documentation
Problem

The short documentation shown by help()/pydoc makes object.__sizeof__() and sys.getsizeof() look almost equivalent, even though they may return different values in practice.

For example, their short descriptions currently read very similarly:

  • sys.getsizeof():

    Return the size of object in bytes.

  • object.__sizeof__():

    "Size of object in memory, in bytes."

From these short descriptions, a user can reasonably assume that both functions report the same value.

Why this is confusing

In practice, they can differ.

sys.getsizeof() may return a larger value than obj.__sizeof__(), because it is not just a direct alias for __sizeof__(). The full documentation for sys.getsizeof() explains the extra behavior, but that distinction is not obvious from the short help output.

This makes the following kind of session surprising:

import sys

class A:
    pass

obj = A()

print(obj.__sizeof__())
print(sys.getsizeof(obj))

A user who relies on help() or short docstrings may expect the first two values to match, but they may not.

Suggestion

It may be helpful to clarify this distinction in the short documentation, so that it is visible without referring to the full documentation.

In particular, it could clarify that:

  • sys.getsizeof() may include additional overhead beyond the value returned by __sizeof__()
Linked PRs
  • gh-146087

Guia de contribuição

Abrir o guia de contribuição

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Direção de pesquisa

Comece comparando a saída curta de ajuda ou pydoc de sys.getsizeof() e object.sizeof(), depois inspecione o PR vinculado gh-146087 para consultar o trabalho que já está em andamento. Está concluído quando as descrições curtas distinguirem claramente sys.getsizeof() de sizeof() e explicarem que overhead adicional pode ser incluído.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
python
Domínio
documentation
Tipo de issue
Documentação
Dificuldade
2/5
Tempo estimado
1-3 horas
Status de atividade
Estagnada
Clareza
Razoavelmente clara
Facilidade para iniciantes
25/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.