Non-empty container types
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
Feature
It would be very helpful to have a way of specifying that a container type must be non-empty.
Pitch
As an example of why this feature would be helpful, consider the following function, average:
from typing import List
def average(numbers: List[float]) -> float:
"""Return the average of a non-empty list of numbers."""
return sum(numbers) / len(numbers)
Rather than relying on exceptions for handling the case when the number of numbers is zero, is seems like something along the lines of the following would be more convenient and more explicit:
from typing import List, NonEmpty
def average(numbers: NonEmpty[List[float]]) -> float:
"""Return the average of a non-empty list of numbers."""
return sum(numbers) / len(numbers)
I don't know anything about the way mypy is implemented so I'm not sure if this is a possible.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
この issue では、NonEmpty[List[float]] と average 関数を例として、Python のコンテナーアノテーション向けの NonEmpty 型を提案しています。まず、mypy に既存の型システムおよび typing 構成要素のサポートを確認してください。issue ではファイルもテストも指定されていません。完了には、空でないコンテナーの不変条件を維持する、合意済みの設計と型チェックが必要です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- devtools
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- 説明が足りない
- 初心者へのやさしさ
- 25/100