Collating list traits fails when only one is given - regression in traitlets 5.13.0
krassowski opened this issue · 2 comments
The regression is caused by a change in traitlets/traitlets.py
file, in Instance
class, in validate
method:
- def validate(self, obj, value):
+ def validate(self, obj: t.Any, value: t.Any) -> T | None:
assert self.klass is not None
+ if self.allow_none and value is None:
+ return value
if isinstance(value, self.klass): # type:ignore[arg-type]
- return value
+ return t.cast(T, value)
else:
self.error(obj, value)
Nothing obviously wrong here, but apparently the Container
logic depends on the error being thrown here 🤷
The self.error()
call was previously making the logic work correctly because the error is excepted to be raised by DeferredConfigString.get_value()
:
traitlets/traitlets/config/loader.py
Lines 390 to 417 in 13de53c
get_value()
calls trait.from_string()
:
traitlets/traitlets/traitlets.py
Lines 3511 to 3519 in 13de53c
which calls validate()
.
So if we pass --ServerApp.a_list=a_value
where a_list = List(allow_none=True)
previously we would get a_list = ['a_value']
and now we are getting a_list = None
.