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
It would be nice to display the class that defines the attribute when we assign an incompatible value to an attribute:
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: