Skip to content

execution order of trait observers #874

Open
@jgunstone

Description

its not clear to me in what order the trait observers get executed and why?
can anyone shed light on this?

class Test(tr.HasTraits):
    a = tr.Bool(default_value=True)
    b = tr.Bool(default_value=True)
    c = tr.Bool(default_value=True)

    @tr.observe("a")
    def _a(self, on_change):
        print(f"a = {self.a}")

    @tr.observe("b")
    def _b(self, on_change):
        print(f"b = {self.b}")

    @tr.observe("c")
    def _c(self, on_change):
        print(f"c = {self.c}")

    def __init__(self, **kwargs):
        super().__init__(**kwargs)


t1 = Test(a=False, b=False, c=False)
print("---")
t2 = Test(c=False, b=False, a=False)

# b = False
# c = False
# a = False
# ---
# b = False
# c = False
# a = False

many thanks

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