ParamSpec: No support for adding keyword-only argument
まだ誰も着手していません。
評価
調査の方向性
まず PEP 612 の却下された代替案と、既存の ParamSpec および Concatenate の仕様を読みます。issue では実装ファイルやテストが指定されていないため、最初に typing-spec の関連するエントリポイントを特定します。完了の条件は、合意された構文と、オプションの keyword-only パラメータの定義済みの動作です。
索引モデルが issue の本文から書いたものです。
説明
I've been looking through PEP 612 but I just wasn't able to find any way to implement behavior that would allow me to do this:
P = ParamSpec("P")
R = TypeVar("R")
def foo(f: Callable[P, R]) -> Callable[P, List[R]]: # Here, the parameters are actually P + optional kw-only int x = 3
def inner(*args: P.args, x: int = 3, **kwargs: P.kwargs) -> List[R]:
results = []
for _ in range(x):
ret = f(*args, **kwargs)
results.append(ret)
return results
return inner
@foo
def bar(p: int):
return p + 2
bar(5) # Acceptable
bar(5, x=8) # Should also be Acceptable
Proposed solution:
Callable[[P.args, x: int = 3, P.kwargs], List[R]]
EDIT: I didn't notice that this was already in rejected alternatives section (I didn't scroll that far), however I still think an implementation like this would be worth adding since I have already encountered the need for this twice and there's simply absolutely no way to handle it.
I'm fine with the proposed syntax suggestion of
Concatenate[("x", int), P]
Though it didn't mention anything about default values, but those could just be handled by a third value in that tuple. It would probably be a lot easier to implement than my proposed suggestion, though to be fair, at least to me, my suggestion looks a bit cleaner.
- 主要言語
- Python
- スター
- 1.8k
- フォーク
- 302
- 平均マージ
- 23時間
- マージ済み PR(30日)
- 8
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
python/typing のほかの issue
-
topic: typing spec
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
topic: typing spec
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
topic: documentation
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
-
topic: documentation
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
-
topic: conformance tests topic: typing spec
難易度 3/5 1〜2日 初心者へのやさしさ 72/100
似ている issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
zostera/django-bootstrap4#894 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
use-agent-os/agent-os#3276 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
zephyrproject-rtos/zephyr#119726 ·
-
area/auth bug comp/agent P3 platform/discord type/security
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
NousResearch/hermes-agent#117848 ·