-
-
Notifications
You must be signed in to change notification settings - Fork 208
Description
In general there's confusion throughout traitlets about what characteristics of traits are or aren't known independently of the class / instance they belong to. As a result, there are many places in the codebase that are effectively copying and posting code from validate(self, obj, value) into their __init__ because obj isn't known at that point. The same is true of default value representations which attempt to get default_value even though the trait may have a make_dynamic_default method, and or get cast via validate after the fact.
In an ideal world, traitlets would have been designed with this gnostic dichotomy in mind, and we might have been able to do Int.validate("one") or repr(List.default()) reliably. Unfortunately though we're stuck in a world where it wasn't. As a result, I would propose that we remove tests that check for valid defaults in the constructors of traits (e.g. Tuple(default_value=5) would not raise) or string representations that use default_value. The former case makes it difficult to generalize much of the logic in traitlets, while the latter is simply misleading.
I'm not sure how tenable this proposal is, but this problem is pervasive in traitlets and makes it increasingly difficult to improve traitlets without breaking these problematic expectations.