Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

`NotRequired[...]` built at runtime for introspection reported as invalid-annotation

Aperta
#5,429 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

@MarcoGorelli ci sta già lavorando.

Dal 29/10/2026.

  • #5450 di @MarcoGorelli — aperta

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
Stack tecnologico
python, rust

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

quansight
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:

Sandbox Link

https://pyrefly.org/sandbox/?project=v2.pZRBCoMwEEWvEtqFCtbsPUQp3apIqEGl1BRNS4t49_6ZqCgFoXSZZPIzk3nzf7XMUtvctHVZow-jObioXL-sbqjw2SKOxp7HMijY0X1T7TU3o0_6FTqGKS1gfTSlIT2SMTXrrakZDskenxIv5RPSyQSBgaNQ0JLoYPmIGfGDwSXhvHRRiL9OqU93CtDhuh2ChBfIiKdqfu-793txchti_Ea4HqApH_BW6EZps4etalFZe-9iKafrpi2lbmRhLp1c3ZBcjXqqmh17LSdcth1k_4HOc8x5W8h5RBxHHFTzRhB3APssjoNNvD4

(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

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di facebook/pyrefly

Tutte le issue di facebook/pyrefly

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.