Clarify the diffrence between object.__sizeof__() and sys.getsizeof() in short documentation/help output
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 35.9k
- PR マージ指標
- PR 指標を取得中
説明
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
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず sys.getsizeof() と object.sizeof() の短いヘルプまたは pydoc の出力を比較し、次に、すでに進行中の作業についてリンク先の PR gh-146087 を確認します。短い説明で sys.getsizeof() と sizeof() の違いが明確に示され、追加のオーバーヘッドが含まれる場合があることが説明されていれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- documentation
- issue の種類
- ドキュメント
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 25/100