Use of generics in requests typing
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 5.1k
- フォーク
- 2.1k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 82
説明
Currently the requests typing makes heavy use of unions. For example the parameter type is:
https://github.com/python/typeshed/blob/f99e8b0615182bb0f17d9d126019d8d72c207ab3/stubs/requests/requests/sessions.pyi#L97-L103
The issue with this approach is that the type system can't keep track of which type has been chosen for a given field. For example, running pyright on this code:
from requests import Session
session = Session()
session.params = {}
reveal_type(session.params)
Shows us that the type system immediately "forgets" that our parameters are definitely in a dictionary:
test.py:5:13 - information: Type of "session.params" is "dict[str | bytes | int | float, str | bytes | int | float | Iterable[str | bytes | int | float] | None]"
0 errors, 0 warnings, 1 information
If we could make Session (as well as other classes such as Request) generic over the parameter type (as well as other fields), then we could keep track of this kind of state. For example, it might look like:
session: Session[dict] = Session()
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
リンクされている requests/requests/sessions.pyi の97~103行付近のセクションから始め、次に Session と Request がどのように型付けされているかを確認してください。提供された pyright の例を使用して、代入後もジェネリックパラメーターの型が具体的なままかどうかを評価してください。提案されたジェネリック設計が対象クラスに対して一貫して定義され、選択されたフィールドの型を保持していれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- tooling
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100