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

Pylance doesn't recognise attributes obtained from `fields`

Aperta
#1,361 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
python
Ambito
tooling

Direzione di ricerca

The issue provides a Python MRE but names no repository files or tests. Start by reproducing the behavior with attrs and Pylance, then inspect how the generated AAttributes type is exposed; done means determining whether attrs can provide the needed typing information or whether this belongs in Pylance.

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

Descrizione

Pyright Typing

Consider this MRE

from attrs import define, fields

@define
class A:
    foo: int
    bar: float

f = fields(A)
print(f.foo)
Attribute(name='foo', default=NOTHING, validator=None, repr=True, eq=True, eq_key=None, order=True, order_key=None, hash=None, init=True, metadata=mappingproxy({}), type=<class 'int'>, converter=None, kw_only=False, inherited=False, on_setattr=None, alias='foo')

This all works fine.

The only thing that isn't working perfectly is Pylance doesn't seem to properly recognise this. It highlights the attribute in white and incorrect hover text is provided.
Untitled

Looking at the types, I found

print(type(f))
<class 'AAttributes'>

But I couldn't find any reference to AAttributes in the codebase.

My question is, is there something that attrs needs to do to make Pylance work here? Or is this a bug/limitation with Pylance and I should open a ticket with them to get support for this?

Thanks.

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.