Skip to content

Attribute assignments through a base class don't call __setattr__ defined in a subclass #1242

Open
python/mypy
#22162

Description

@rheard
class Base:
    def __init__(self) -> None:
        self.y = 0

    def set_y(self) -> None:
        self.y = 1


class Derived(Base):
    def __setattr__(self, name: str, value: object) -> None:
        print("setattr", name, value)
        super().__setattr__(name, value)


def set_through_base(b: Base) -> None:
    b.y = 2


d = Derived()
d.set_y()
set_through_base(d)

Interpreted, this prints setattr y 0, setattr y 1 and setattr y 2. Compiled with current master, it prints nothing.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions