`TypedDict.copy()` falls back to `dict[str, object]`
@HarikumarS1106 がすでに取り組んでいます。
2026年10月5日 から。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 35/100
調査の方向性
Start by reproducing the bound and constrained type-variable examples for TypedDict.copy() from the issue or linked sandbox, then read the referenced typing specification section. Determine the intended result for each example and make pyrefly's revealed type consistent with that decision, with coverage for the reported cases.
索引モデルが issue の本文から書いたものです。
説明
Describe the Bug
Calling copy on a TypedDict is not described in https://typing.python.org/en/latest/spec/typeddict.html#specific-operations
I've found that pyrefly, pyright and ty all disagree on how this should work with type variables.
Show code block
from __future__ import annotations
from typing_extensions import TypedDict, assert_type, reveal_type
class A(TypedDict, closed=True):
a: int
class B(TypedDict, closed=True):
b: str
a = A(a=1)
b = B(b="b")
a_copy = a.copy()
b_copy = b.copy()
assert_type(a, A)
assert_type(b, B)
def copy_bound[T: A | B](obj: T) -> T:
result = obj.copy() # ty: ignore[invalid-argument-type]
reveal_type(result)
# pyright 'Type of "result" is "A* | B*"'
# ty 'Revealed type: `Unknown`'
# pyrefly 'revealed type: dict[str, object]'
return result
def copy_constrained[T: (A, B)](obj: T) -> T:
result = obj.copy()
reveal_type(result)
# pyright 'Type of "result" is "A* | B*"'
# ty 'Revealed type: `T@copy_constrained`'
# pyrefly 'revealed type: dict[str, object] & T'
return result
I'm reporting here as I found the pyrefly output the most surprising.
Maybe this needs to be defined in the typing spec?
My actual use case for this was a bound type variable, over a union with 20-30 members that all use closed=True.
Sandbox Link
(Only applicable for extension issues) IDE Information
No response
- 主要言語
- Rust
- スター
- 7.2k
- フォーク
- 578
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
facebook/pyrefly のほかの issue
-
sqlalchemy
難易度 4/5 3〜5日 初心者へのやさしさ 55/100
-
typechecking
難易度 4/5 3〜5日 初心者へのやさしさ 57/100
-
quansight
難易度 3/5 半日 初心者へのやさしさ 55/100
-
Version-gated early exits: `from copy import replace` is accepted but `copy.replace` is rejectedオープンquansight
難易度 4/5 3〜5日 初心者へのやさしさ 30/100
-
`type[Self]` converted to a callable drops constructor signature対応中かも @crypt0lith が 2 日前に担当しました。 オープンhas-open-pr typechecking
facebook/pyrefly の issue をすべて見る
似ている issue
-
SPLADE `/embed_sparse` output depends on the other inputs in the batch (candle BertModel / DistilBertModel)対応中かも @0z5a が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
huggingface/text-embeddings-inference#979 ·
メンテナーはふだん 1 日以内に返信
-
good first issue help wanted
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
servo/rust-smallvec#874 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 94/100
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
メンテナーはふだん 2 日以内に返信
-
ci enhancement need-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
メンテナーはふだん 1 日以内に返信