ipython / ipython/traitlets

Feature request: combine callback calls after holding notifications

未关闭
#450 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Python
星标
653
派生
217
平均合并
2 天 21 小时
30 天内合并 PR
2

描述

In the following example:

```python
from traitlets import HasTraits, Integer

class State(HasTraits):
a = Integer()
b = Integer()

def callback(*args, **kwargs):
print(args, kwargs)

s = State()
s.observe(callback)
with s.hold_trait_notifications():
s.a = 1
s.b = 2
```

Callback gets called twice. However, it would be nice to have a way to minimize the number of callback calls when exiting the context manager.

The reason I ask about this is because I would like to consider transitioning [glue](http://www.glueviz.org) from using [echo](https://github.com/glue-viz/echo), which is our own trait-like library by traitlets. The case I describe above is common in our code, where we change a bunch of traits and then want to e.g. force a redraw (but only one and not one per trait).

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。