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
-
essnmx good first issue
难度 1/5 1 小时以内 新手友好度 95/100
-
难度 2/5 1-3 小时 新手友好度 65/100
syfoud/Simulated_Scepter#174 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
Giskard-AI/giskard-oss#2840 · 1 条评论 ·
-
A claim comment carrying the issue number is silently declined while the workflow reports success 未关闭area: repo bug perceived difficulty: 2
难度 2/5 1-3 小时 新手友好度 70/100
-
难度 2/5 1-3 小时 新手友好度 75/100
yeti-platform/yeti#1380 ·