Relax requirement on the signature of handler for traits.observation.observe.observe
- Dominant language
- Python
- Stars
- 462
- Forks
- 90
- PR merge metrics
- No merged PRs in 30d
Description
For `traits.observation.observe.observe`, the `handler` argument signature can be relaxed so long as `dispatcher` can collaborate with it:
https://github.com/enthought/traits/blob/72b1fe35ff1618fd01554102243266bd35b2ca95/traits/observation/observe.py#L29-L49
Proposed new documentation:
```
handler : callable(*args, **kwargs)
User-defined callable to invoke when there is a change event.
A weak reference is held for the handler such that it can be garbage collected.
...
dispatcher : callable(handler, event)
Callable for invoking the user-defined handler.
The first argument is the `handler` given to this function.
The second argument is an event object representing the change.
Its type and content depends on the change.
```
So long as `dispatcher` can handle the signature of `handler`, it does not matter what `handler` call signature is.
I believe this behaviour is already true. We just need to document and test it in order to formally support it.
The motivation for this issue comes from an attempt to reimplement Envisage's `ExtensionRegistry`. If the signature is relaxed, we can call `observe(..., handler=listener, ..., dispatcher=dispatcher)` where `listener` has a signature of `(extension_registry, extension_point_event)` and `dispatcher` can be responsible for calling `listener` with the appropriate values. We want to avoid holding a strong reference to the `listener`. `observe` already does that for `handler`.
This proposal does NOT apply to the `handler` signature on `HasTraits.observe`. This is because `HasTraits.observe` offers a convenient mapping from str to dispatcher where the dispatcher requires the `handler(event)` signature.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.