Support `Any` as an alias for `object` to describe a default typeclass implementation
まだ誰も着手していません。
評価
調査の方向性
この issue では実装ファイルやテストが指定されていません。まず @render.instance(object) の背後にある処理と、既存の typeclass インスタンステストを見つけ、次に object のデフォルトがどのように認識されるかを追跡してください。完了条件は、@render.instance(Any) が @render.instance(object) と同等に動作し、例ではフォールバック実装がディスパッチされることです。
索引モデルが issue の本文から書いたものです。
説明
Context. In order to define a default implementation (the one used if no other implementation matches), we currently have to write something like this:
from classes import typeclass
@typeclass
def render(data_value) -> str:
"""Render a data value nicely."""
@render.instance(int)
def _render_int(data_value: int) -> str:
return f'This is an integer: {data_value}'
@render.instance(object)
def _render_int(data_value: object) -> str:
return f'No idea what this is: {data_value}'
assert render('BADOOM') == 'No idea what this is: BADOOM'
(this script should be runnable as-is.)
Decision. Support Any as a special case to replace object:
@render.instance(Any)
def _render_int(data_value: Any) -> str: # type: ignore
return f'No idea what this is: {data_value}'
Consequences.
- Pro: The code will look a little bit more straightforward;
- Contra:
mypywith common settings might be unhappy aboutAnybeing used, but that can be silenced withtype: ignoreI suppose.
- 主要言語
- 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 ·