Clarify the diffrence between object.__sizeof__() and sys.getsizeof() in short documentation/help output
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 77.2k
- Forks
- 35.9k
- Métricas de merge de PR
- Métricas de PR pendientes
Descripción
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
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza comparando la salida breve de ayuda o pydoc de sys.getsizeof() y object.sizeof(), y después inspecciona el PR vinculado gh-146087 para consultar el trabajo que ya está en curso. Se considera terminado cuando las descripciones breves distinguen claramente sys.getsizeof() de sizeof() y explican que puede incluirse overhead adicional.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- documentation
- Tipo de issue
- Documentación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 25/100