Should dict() constructor overloads be more permissive?
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 5.1k
- フォーク
- 2.1k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 82
説明
Current constructor overloads are here:
Someone took care to allow specific positive case, and to block specific negative case.
Many potential valid uses have fallen through the cracks:
dict([[1, 2]])
dict("AT TA GC CG".split())
dict([["str", b"bytes"]])
My understanding of the issue is that there's no way to specify sequence length (other than a tuple) in a type hint, that is there's no syntax to hint ["a", "b"] vs ["a", "b", "c"].
This brings a philosophical question: what side should typeshed err on when type hint syntax is not precise enough?
- type whatever Python may accept run time, or
- restrict users to what Python is guaranteed to accept at run time?
It was mentioned at https://github.com/microsoft/pyright/issues/7382 that type checkers trust typeshed, and thus the question belongs here.
My personal preference would be for permissive type hints in these cases.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
リンクされている dict() コンストラクターのオーバーロードがある stdlib/builtins.pyi から始め、issue の呼び出し例と比較してください。関連する型チェッカーがそれらのケースをどのように扱うかを確認し、そのうえで、意図されている方針が実行時に有効なより広範な入力を受け入れることかどうかを判断してください。完了には、合意されたオーバーロード設計と対応する検証が必要です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- tooling
- issue の種類
- 機能追加
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 25/100