Better insight on dictionary of traits instantiation

Open Beginner friendly
#549 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
1-3 hours
Newbie friendliness
65/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
python
Domain
backend

Research direction

Inspect traitlets/traitlets.py at lines 2835-2845, focusing on the key and value validation error handlers. Preserve the original TraitError message when constructing the element error, and verify that failures for both keys and values include that context.

Written by the indexing model from the issue text.

Description

In the code, when an instance of traits dictionary is created, if an error occurs in a element construction, the original error message is not used. This makes it more complicated to figure out what went wrong.

https://github.com/ipython/traitlets/blob/32ced29b0ab06914ff92e9bdcd8806536633d701/traitlets/traitlets.py#L2835-L2845

It would be nice to add the catch error message to the newly created element error.

 if key_trait: 
     try: 
         key = key_trait._validate(obj, key) 
     except TraitError as error: 
-         self.element_error(obj, key, key_trait, 'Keys') 
+         self.element_error(obj, key, key_trait, str(error), 'Keys') 
 active_value_trait = per_key_override.get(key, value_trait) 
 if active_value_trait: 
     try: 
         v = active_value_trait._validate(obj, v) 
     except TraitError as error: 
-         self.element_error(obj, v, active_value_trait, 'Values') 
+         self.element_error(obj, v, active_value_trait, str(error), 'Values') 
Dominant language
Python
Stars
653
Forks
217
Avg merge
2d 21h
Merged PRs (30d)
2

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ipython/traitlets

All issues in ipython/traitlets

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.