Semantic and documentation of Interpreter.prepare_main()
還沒有人認領這個 Issue。
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 35.9k
- PR 合併指標
- PR 指標待擷取
描述
Interpreter.prepare_main() is documented as:
.. method:: prepare_main(ns=None, **kwargs)
Bind objects in the interpreter's :mod:`!__main__` module.
Some objects are actually shared and some are copied efficiently,
but most are copied via :mod:`pickle`. See :ref:`interp-object-sharing`.
But it is not clear what ns is, and how kwargs is related. A module and a class are nemspaces, so can you pass them? Or the SimpleNamespace instance? No. Looking at the code, ns can only be None, a mapping or an iterable of pairs. Is it what was intended? Than it should be documented.
But accepting an iterable of pairs may be not intended. This can hardly be called a namespace. Then the code should be changed from
ns = dict(ns, **kwargs) if ns is not None else kwargs
to
ns = {**ns, **kwargs} if ns is not None else kwargs
And was it necessary to accept None? This is error-prone, as you can accidentally get None instead of a valid value (missing return or missing initialization). {} could be used as a default value, it is fine if it is not mutated. If exclude None, it can be simply written as:
ns = {**ns, **kwargs}
And I suggest to to change the name of the parameter, as it is not a general namespace. "dict" or "mapping" would better reflect its type. "updates" or "changes" could also be used, but then we should also rename "kwargs" to "updates2" or "changes2". Since this is positional-only parameter, changing the name does not break user code.
cc @ericsnowcurrently
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
從 Interpreter.prepare_main() 的文件及其實作著手,尤其要弄清楚 ns 和 kwargs 如何組合。判斷預期接受的輸入類型,以及是否應變更參數名稱或行為,然後更新文件或相關程式碼,並新增或調整相關測試,讓 API 語意明確。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- documentation
- Issue 類型
- 文件
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100