ipython / ipython/traitlets

Feature request: combine callback calls after holding notifications

Đang mở
#450 2 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Python
Star
653
Fork
217
Merge trung bình
2 ngày 21 giờ
Pull request đã merge (30 ngày)
2

Mô tả

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).

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.