nucleic / enaml

Declarative User Interfaces for Python
http://enaml.readthedocs.io/en/latest/
Other
1.52k stars 130 forks source link

Implement hash and eq for bound decl func #517

Closed frmdstryr closed 1 year ago

frmdstryr commented 1 year ago

Currently if you use observe with a decl func it is impossible to remove the observer unless you clear all observers. This fixes that.

A simple example to show the problem.

from atom.api import Atom, Str
from enaml.widgets.api import Window, Container, Label, Field, PushButton

class Model(Atom):
    output = Str()

enamldef Main(Window): window:
    attr model = Model()
    func decl_print(x):
        print(x)

    Container:
        PushButton:
            text = "Add observer"
            clicked :: model.observe("output", decl_print)
        PushButton:
            text = "Remove observer"
            clicked :: model.unobserve("output", decl_print)
        Field:
            submit_triggers = ["auto_sync"]
            text := model.output

The hash function is based on cpythons method_hash (see https://github.com/python/cpython/blob/81f7359f67a7166d57a10a3d5366406d9c85f1de/Objects/classobject.c#L298)

MatthieuDartiailh commented 1 year ago

Can you add a changelog entry ?

codecov-commenter commented 1 year ago

Codecov Report

Merging #517 (fa381bb) into main (b6935e6) will increase coverage by 0.00%. The diff coverage is 81.48%.

:mega: This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #517 +/- ## ======================================= Coverage 73.21% 73.22% ======================================= Files 296 296 Lines 25810 25837 +27 Branches 3648 3650 +2 ======================================= + Hits 18896 18918 +22 - Misses 5829 5834 +5 Partials 1085 1085 ```
MatthieuDartiailh commented 1 year ago

Thanks