Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Improve motivating example for Maybe

オープン
#760 コメント 2 件 リアクション 3 件 担当者 0 名 GitHub で見る

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

評価

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

調査の方向性

まず、現在の Maybe の動機付けの例を含むドキュメントのセクションを見つけます。issue ではファイルもテストも指定されていません。例を記載されている Python の代替案と比較し、想定されるユースケースを明確にします。ドキュメントが、曖昧な None の返却を通常のエラー処理として扱わずに、説得力のある動機付けを示していれば完了です。

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

説明

bug documentation

The current example motivating the use of Maybe is somewhat misleading because it solves a made-up problem:

Alleged original "python" code:

if user is not None:
     balance = user.get_balance()
     if balance is not None:
         credit = balance.credit_amount()
         if credit is not None and credit > 0:
             discount_program = choose_discount(credit)

Alleged "better" solution using Maybe:

discount_program: Maybe['DiscountProgram'] = Maybe.from_optional(
    user,
).bind_optional(  # This won't be called if `user is None`
    lambda real_user: real_user.get_balance(),
).bind_optional(  # This won't be called if `real_user.get_balance()` is None
    lambda balance: balance.credit_amount(),
).bind_optional(  # And so on!
    lambda credit: choose_discount(credit) if credit > 0 else None,
)

Usual python code solving this exact problem:

try:
    discount_program = choose_discount(user.get_balance().credit_amount())
except AttributeError:
    pass

The example is based on the very bad habit of signaling errors by return values, e.g. returning None.

No sane (python) developer would write a function that returns None in case of an error unless there is good reason for it, it is properly documented and returning None immediately and unambiguously tells the caller what went wrong. When exceptions occur, exceptions should be raised.

For example, credit_amount() returning None conveys no meaning at all. No credit? Credit amount == 0? Credit amount < 0? Raccoons taking over the world?

And even if one had to use flawed 3rd party code like this, there is a shorter and more concise version to handle this without Maybe.

I believe there is a legitimate use case for Maybe, but this is not it.

主要言語
Python
スター
4.4k
フォーク
154
平均マージ
3時間 5分
マージ済み PR(30日)
22

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

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

はじめの一歩

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

dry-python/returns のほかの issue

dry-python/returns の issue をすべて見る

似ている issue

Python の issue をもっと見る

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

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