traitlets icon indicating copy to clipboard operation
traitlets copied to clipboard

traitlets Dict does not observe value changes after initial key / value assigments

Open mpenning opened this issue 6 months ago • 2 comments

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

In both cases below, a TraitError is not thrown, even though None is assigned to a Unicode() field after initialization...

from traitlets import HasTraits, Dict, Unicode

class Foo(HasTraits):
    data = Dict(per_key_traits={"a_key": Unicode()})

class Bar(HasTraits):
    data = Dict(key_trait=Unicode(), value_trait=Unicode())

foo = Foo()
foo.data = {"a_key": "a_value"}
# I think this should throw a TraitError...
foo.data["a_key"] = None

bar = Bar()
bar.data = {"a_key": "a_value"}
# I think this should throw a TraitError...
bar.data["a_key"] = None

mpenning avatar May 11 '25 23:05 mpenning

Duplicate of https://github.com/ipython/traitlets/issues/557

rmorshea avatar May 13 '25 00:05 rmorshea

I suggest taking a look at Spectate

rmorshea avatar May 13 '25 00:05 rmorshea