`TypedDict.copy()` falls back to `dict[str, object]`
@HarikumarS1106 ci sta già lavorando.
Dal 5/10/2026.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 35/100
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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
- Lingua principale
- Rust
- Stelle
- 7.2k
- Fork
- 578
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di facebook/pyrefly
-
typechecking
Difficoltà 3/5 1-2 giorni Idoneità per principianti 56/100
-
pytorch typechecking
Difficoltà 3/5 1-2 giorni Idoneità per principianti 56/100
-
typechecking
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
-
narrowing typechecking
Difficoltà 4/5 3-5 giorni Idoneità per principianti 49/100
-
typechecking
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
Tutte le issue di facebook/pyrefly
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
apache/datafusion-iceberg#100 ·
I maintainer di solito rispondono entro 1 giorno
-
[Bug]: cua-driver skill fails Agent Skills frontmatter validationForse già presa @Mearman l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
-
area/tools bug session-analysis
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 80/100
oracle/rust-oracledb#66 ·
-
`PrimitiveArray::validate_decimal_precision` rejects every decimal array with a negative scaleAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno