python / python/cpython

types.MappingProxyType states that proxy[key] will throw a KeyError, but that is not always true

オープン
#117,956 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

docs
主要言語
Python
スター
77.2k
フォーク
35.9k
PR マージ指標
PR 指標を取得中

説明

Documentation

In the documentation, it states proxy[key] will:

Return the item of the underlying mapping with key key. Raises a KeyError if key is not in the underlying mapping.

https://docs.python.org/3/library/types.html#types.MappingProxyType

However, it is possible to get an AttributeError instead, and in fact, unit tests for the dataclasses module require this to be true (metadata in dataclasses.field is wrapped in a mapping proxy):

https://github.com/python/cpython/blob/5f4c7cf3f49629bcf890c305e0a90ffd708110a2/Lib/test/test_dataclasses/__init__.py#L2065-L2066

The unit tests above are from Python3.12.

Looks like the CPython source code only forwards the getitem call to the inner mapping:

https://github.com/python/cpython/blob/5f4c7cf3f49629bcf890c305e0a90ffd708110a2/Objects/descrobject.c#L1042-L1046

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

リンク先の Python ドキュメントページにある MappingProxyType のドキュメントから始め、続いてその記述を、参照されている dataclasses のテストおよび Objects/descrobject.c の実装と比較してください。テストと実装で示されている例外の動作をドキュメントが正確に説明していれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
documentation
issue の種類
ドキュメント
難易度
1/5
見積もり時間
1時間未満
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
58/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。