Use of `AttrsInstance` protocol is incompatible with type checkers other than mypy

Aperta
#996 8 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
32/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
python
Ambito
tooling

Direzione di ricerca

Start by reproducing the type errors in fields and asdict with type checkers other than mypy, then read the AttrsInstance protocol and the attrs mypy plug-in behavior. Compare removing attrs_attrs from the protocol with injecting it through the plug-in; done means these core functions type-check by default outside mypy without breaking the attrs plug-in path.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Typing

The latest release introduced the AttrsInstance protocol with one attribute, __attrs_attrs__, which replaced Any in the signature of various core functions. The __attrs_attrs__ attribute is "injected" by the attrs mypy plug-in; other type checkers have no knowledge of this attribute and adding attributes to the type definition of a dataclass-like class is not supported by dataclass_transform. Therefore, functions such as fields and asdict generate type errors by default in all type checkers other than mypy. I am not familiar with mypy plug-ins but I assume one alternative would be to remove the attribute from the protocol definition and inject it dynamically from the plug-in, the way it's done for the attrs class. Longer term, an extension to dataclass_transform could be sought.

Lingua principale
Python
Stelle
5.8k
Fork
480
Merge medio
2h 15m
PR unite (30g)
2

Guida per i contributori

Apri la guida per i contributori

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 python-attrs/attrs

Tutte le issue di python-attrs/attrs

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.