Support `Any` as an alias for `object` to describe a default typeclass implementation
還沒有人認領這個 Issue。
評估
研究方向
此 issue 沒有指出實作檔案或測試。先找出 @render.instance(object) 背後的處理邏輯以及現有的 typeclass instance 測試,然後追蹤 object 預設值是如何被辨識的。完成的標準是:@render.instance(Any) 的行為與 @render.instance(object) 等效,同時範例會分派至 fallback implementation。
由索引模型根據 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 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 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 個 reaction ·
-
bug
難度 2/5 1-3 小時 新手友好度 35/100
dry-python/classes#386 ·
查看 dry-python/classes 的全部 Issue
相似的 Issue
-
bug
難度 2/5 1-3 小時 新手友好度 75/100
stephrobert/dsoxlab#238 ·
-
難度 2/5 1-3 小時 新手友好度 75/100
-
難度 2/5 1-3 小時 新手友好度 75/100
sublimehq/package_control#1780 ·
-
難度 2/5 1-3 小時 新手友好度 65/100
-
難度 2/5 1-3 小時 新手友好度 70/100
nwg-piotr/nwg-displays#145 ·