dry-python / dry-python/classes

Support `Literal` types

未關閉
#274 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
enhancement
主要語言
Python
星號
730
分支
30
PR 合併指標
30 天內沒有已合併 PR

描述

After we have `delegate` in-place we can use `Literal` types.

But, now they are not supported.
Ideally, something like this should work:

```python
from classes import typeclass, AssociatedType, Supports
from typing_extensions import Literal

class SomeDelegate(object):
... # TODO: write proper `__instancecheck__`

class A(AssociatedType):
...

@typeclass(A)
def some(instance) -> int:
...

@some.instance(Literal[1], delegate=SomeDelegate)
def _some_tuple(instance: Literal[1]) -> int:
return instance

def test(i: Supports[A]):
return some(i)

some(1)
```

貢獻指南

開啟貢獻指南

研究方向

先追蹤 `typeclass`、`AssociatedType`、`Supports` 和 `@some.instance` 如何處理委派型別,接著將這條路徑與 `Literal[1]` 範例進行比較。完成的標準是該範例能通過型別檢查,且 `some(1)` 能透過 `Literal` 註冊正確解析,同時保留現有的委派行為。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
python
領域
tooling
Issue 類型
功能
難度
4/5
預估耗時
3-5 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
38/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。