Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Right now nested traits have pretty horrid error messages.
The following code produces three different tracebacks with three bad error messages:
Error messages (tracebacks excluded):
The First two messages, while accurate, don't have a trait name associated with them which makes them confusing to read. The last one has a trait name but is inaccurate since it complains of a list being provided to a
List
trait!Solution
A generic
TraitType.error(obj, value, error=None)
method that can be used to easily handle nested errors. To use it, one only needs to catch the nested error in a parent trait and pass it toerror
.With the proposed changes, the code above would create one concise traceback and message:
Notes
There is an added utility file
descriptions.py
which has a newdescribe
function in addition to others that were previously present intraitlets.py
likeadd_article
orrepr_type
. Thedescribe
function provides a common way to represent a value as a readable string (see docstring for use details).