ipython / ipython/traitlets

copy(HasTraits) creates a clone with shared state from the original

Đang mở
#481 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ả

Actually the results of using `copy()` on a `Hastrait` with [borged](https://www.google.it/search?q=python+borg) trait values:

```python
from copy import copy

class C(HasTraits):
a = Int()

c = C(a=1)
copy(c).a = 2
assert c.a == 1 # This FAILS because it is also 2!
```

## Suggested solution
I guess we need this line:
```python
d['_trait_values'] = self._trait_values.copy()
```
in `HasTraits.__getstate__()`:
https://github.com/ipython/traitlets/blob/3164ffb43167e9d1688046fbe0aefa424af5b58d/traitlets/traitlets.py#L1084-L1091

And i'm wondering whether the lock must no be shared, either:
```python
d['_cross_validation_lock'] = False
```

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.