Skip to content

For incompatible attribute assignment, show class that defines attribute #2500

@JukkaL

Description

@JukkaL

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions