Prevent an implementation for `int` class from operating on `bool` values
まだ誰も着手していません。
評価
調査の方向性
まず classes 0.4.0 で例を再現し、次に typeclass の宣言と render.instance(int) の登録から dispatch を追跡します。render(True) が int の実装を使用せず、代わりに未指定の bool のケースに対して NotImplementedError を送出するようになれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Context. Consider the following piece of code.
from classes import typeclass
@typeclass
def render(data_value) -> str:
"""Pretty-print a value."""
@render.instance(int)
def _render_int(data_value: int) -> str:
return f'🔢 {data_value}'
render(True) == '🔢 True'
(this should be runnable as-is on classes 0.4.0.)
I would have expected this code to fail with a NotImplementedError because the bool case wasn't specified; but instead, that case is handled by the int implementation because
In [3]: issubclass(bool, int)
Out[3]: True
Decision. In an int implementation, recognize if the provided value is actually a bool and refuse to process that value.
Consequences. I have been writing in Python for quite a few years now and I might even have encountered this relationship between int and bool types before, but that is not quite a type of thing that I keep in my short-term memory to be able to instantly recognize.
I believe this change can help avert bugs which might be hard to trace otherwise.
- 主要言語
- Python
- スター
- 730
- フォーク
- 30
- PR マージ指標
- 30日以内にマージされた PR はありません
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
dry-python/classes のほかの issue
-
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
dry-python/classes#496 ·
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 45/100
dry-python/classes#494 ·
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 52/100
dry-python/classes#492 · コメント 2 件 ·
-
bug
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
dry-python/classes#481 · コメント 5 件 · リアクション 4 件 ·
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 35/100
dry-python/classes#386 ·
dry-python/classes の issue をすべて見る
似ている issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 90/100
learningequality/ricecooker#747 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
BSData/horus-heresy-3rd-edition#3171 ·
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
run-llama/llama_index#23199 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
KhronosGroup/glTF-Blender-IO#2769 ·