Skip to content

Any way to make this work with mutable data structures? #252

@zulrang

Description

@zulrang
  • psygnal version: 0.9.5
  • Python version: 3.11.6
  • Operating System: Ubuntu 22.04.3

Description

After connecting events to mutable types, I would expect that events are called when they are mutated.

What I Did

from psygnal import EventedModel


class MyModel(EventedModel):
    data: dict = {}
    values: list[int]

model = MyModel(data={'foo': 'bar'}, values=[1, 2, 3])
model.events.data.connect(lambda v: print(f"updated data: {v}"))
model.events.values.connect(lambda v: print(f"updated values: {v}"))

model.data['test'] = 'fail'
model.values.append(4)

This doesn't print anything.

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