python / python/mypy

attrs plugin does not implement the new attributes collection algorithm

Aperta
#16,014 0 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

bug topic-attrs
Lingua principale
Python
Stelle
20.6k
Fork
3.3k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

Bug Report

The attrs plugin does not implement the new attributes collection algorithm that is enabled with @attr.s(collect_by_mro=True) in the old API and is the only option in the new API.

To Reproduce

(mypy-play.net does not have stubs for attrs)

from attrs import define, field

@define
class A:
    f: int = field(kw_only=True)

@define
class B(A):
    pass

@define
class C(A):
    f: int = field()

@define
class D(B, C):
    pass

# D(f: int) for attrs.define, but D(*, f: int) for attr.s
d = D(123)
print(d.f)

Expected Behavior

The signature for D should be D(f: int), so this should type check. It works fine at run time.

Actual Behavior

attrs_mro.py:20: error: Too many positional arguments for "D"  [misc]

I get the same error if I replace @define and field with @attrs(collect_by_mro=True) and attrib from the old namespace respectively. Note that this behavior is correct when @attrs is used without collect_by_mro=True.

Your Environment

  • Mypy version used: 1.5.1
  • Python version used: 3.11

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.

Direzione di ricerca

Inizia con mypy's attrs plugin e riproduci l'esempio segnalato di ereditarietà multipla usando attrs.define, field e collect_by_mro=True. Confronta la firma del costruttore inferita con il comportamento previsto di D(f: int), quindi aggiungi o aggiorna la copertura in modo che la chiamata posizionale superi il controllo dei tipi, mentre il comportamento esistente di non-collect_by_mro rimanga corretto.

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

Valutazione

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

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.