Skip to content

Priority is not respected between different callback types #51

Open
@Carifio24

Description

@Carifio24

Describe the bug
Priority is not respected between the different callback types (e.g. one-argument vs. two-argument callbacks). While priority is respected within each callback type, a one-argument callback is always called before a two-argument callback, regardless of priority.

To Reproduce
Here's an example script to demonstrate this issue. Run this, and you should see the one-argument callback get run first each time test.x is updated, despite the higher priority of the two-argument callback

from echo import add_callback, CallbackProperty

class Test:
    x = CallbackProperty(0)

test = Test()

def cb_onearg(value):
    print(f"cb_onearg called with {value}")

def cb_twoarg(old, new):
    print(f"cb_twoarg called with old: {old}, new: {new}")


add_callback(test, "x", cb_onearg, priority=1)
add_callback(test, "x", cb_twoarg, echo_old=True, priority=1000)


test.x = 2
test.x = 7

Expected behavior
I would expect the priority to be respected across all callbacks.

Details:

  • Operating System: Ubuntu 22.04
  • Python version: Python 3.11.5
  • Echo version: 0.11
  • How you installed: pip

Additional context
I think the issue comes from here, where we iterate over the callback containers separately. I haven't had a chance to look into this too much yet, but I guess rather than using the iterator, we could use each container's callbacks member (this includes the priority, the iterator does not) and then re-sort ourselves inside of notify.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions