`NotRequired[...]` built at runtime for introspection reported as invalid-annotation
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 48/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Ambito
- developer-experience, tooling
Direzione di ricerca
Start by reproducing the reported diagnostic with the supplied Python example and sandbox link. Trace how Pyrefly validates NotRequired subscripts in runtime expressions, then compare that behavior with the reported type checker results. Done means the example no longer reports invalid-annotation while invalid uses remain diagnosed.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Describe the Bug
from typing import Any, get_origin
from typing_extensions import NotRequired
def mark_optional(hints: dict[str, Any]) -> dict[str, Any]:
return {key: NotRequired[hint] for key, hint in hints.items()}
assert get_origin(mark_optional({"a": int})["a"]) is NotRequired
$ pyrefly check t.py
ERROR `NotRequired` is not allowed in this context [invalid-annotation]
--> t.py:7:18
|
7 | return {key: NotRequired[hint] for key, hint in hints.items()}
| ^^^^^^^^^^^^^^^^^
INFO 1 error
other type checkers are fine with it
In this example, NotRequired is used for runtime checks. An example of where this pattern is used is in huggingface-hub:
- https://github.com/huggingface/huggingface_hub/blob/a43cbe33148ae6f7ca27568922c1968b69e822d8/src/huggingface_hub/dataclasses.py#L337-L352
- https://github.com/huggingface/huggingface_hub/blob/a43cbe33148ae6f7ca27568922c1968b69e822d8/src/huggingface_hub/dataclasses.py#L479-L482
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
-
documentation
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 82/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 58/100
-
narrowing typechecking
Difficoltà 4/5 1-2 giorni Idoneità per principianti 48/100
-
django language-server
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
-
Polars:`Annotated[pl.DataFrame, S]` does not resolve when `S` is a type var bound to a schema classApertadataframe
Difficoltà 4/5 1-2 giorni Idoneità per principianti 57/100
Tutte le issue di facebook/pyrefly
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno
-
compiler P4 perf
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
HerringtonDarkholme/hd-lang#1044 ·
I maintainer di solito rispondono entro 1 giorno
-
good first issue help wanted r-docs
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
servo/rust-smallvec#824 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
akitaonrails/ai-usagebar#552 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100