ipython / ipython/traitlets

traitlets Dict with per_key_traits should be more specific in a TraitError

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

I'm using `traitlets` version 5.14.3 and Python 3.12.3...

- The error raised by `Dict()` with `per_key_traits` should specify the offending key name in the error.
- The error raised by `Dict()` with `per_key_traits` doesn't handle nested dicts well

Example:

```python
from traitlets import HasTraits, Dict, Unicode

class Foo(HasTraits):
bar = Dict(per_key_traits={"this": Unicode(), "that": Dict(per_key_traits={"that": Unicode()})})

foo = Foo()
# key that should be a Dict()...
foo.bar = {"this": "valid", "that": False}
```

The error raised is:
```
traitlets.traitlets.TraitError: Values of the 'bar' trait of a Foo instance must be a dict, but a value of False was specified.
```

It would be better if it specified the offending chain of keys in the error... Example:
```
traitlets.traitlets.TraitError: Value of bar['that'] for a Foo instance must be a dict, but the specified value at bar['that'] was 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.