Clarify the diffrence between object.__sizeof__() and sys.getsizeof() in short documentation/help output
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 77.2k
- Fork
- 35.9k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia confrontando l'output breve dell'help o di pydoc per sys.getsizeof() e object.sizeof(), quindi esamina la PR collegata gh-146087 per il lavoro già in corso. Il lavoro è completato quando le descrizioni brevi distinguono chiaramente sys.getsizeof() da sizeof() e spiegano che può essere incluso un overhead aggiuntivo.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- documentation
- Tipo di issue
- Documentazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 25/100