For incompatible attribute assignment, show class that defines attribute

Aperta
#2,500 2 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
25/100
Tipo di issue
Funzionalità
Chiarezza
Da chiarire
Stato di attività
Ferma
Stack tecnologico
python
Ambito
devtools

Direzione di ricerca

Use the examples in the issue to define when incompatible-attribute errors should name the defining class, and whether the original file and line should be included. The issue names no files or tests, so first locate the incompatible-attribute diagnostic and its existing coverage; done means the selected cases produce the intended message without unnecessary verbosity in same-class assignments.

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

Descrizione

feature good-second-issue priority-1-normal topic-usability

It would be nice to display the class that defines the attribute when we assign an incompatible value to an attribute:

class A:
    a = 1

class B(A):
    a = ''  # Show that 'a' was defined in 'A' (in addition to the current message)

class C(A): pass

c = C()
c.a = ''   # Again, maybe show that 'a' was defined in 'A'

Maybe also show the file and line on which the attribute was originally defined. However, we probably don't want these verbose messages in the body of a class if the attribute definition is in the same class, as the error is probably clear enough based on immediate context:

class A:
    a = 1

    def f(self) -> None:
        self.a = ''   # The current message is probably just fine, as the context is clear
Lingua principale
Python
Stelle
20.6k
Fork
3.3k
Merge medio
1g 18h
PR unite (30g)
54

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/mypy

Tutte le issue di python/mypy

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.