TraitDict should have an item_validator rather than key_validator and value_validator
- Dominant language
- Python
- Stars
- 462
- Forks
- 90
- PR merge metrics
- No merged PRs in 30d
Description
Currently the new `TraitDict` expects to be supplied a separate `key_validator` and a `value_validator`. We should perhaps be using a single `item_validator` which is given both the key and the value and is expected to return a validated key, value pair.
As motivation, Python 3.8 has the TypedDict where certain keys are expected to hold certain values. With separate validators we can’t implement something like this in Traits, because the value validator doesn’t know what key it is validating.
On the other hand, we can easily write an item validator which calls out to separate key and value validators that are supplied to it in its constructor.
An alternate approach might be to keep the separate validators, but to pass the key to the value validator and the value to the key validator. There is then a secondary issue of which to do first and whether to pass the validate value of the first to the second...
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by locating TraitDict and its current key_validator and value_validator API. Compare the proposed item_validator design with the alternate approach, including validation order and return semantics. Done requires a settled API choice and corresponding validator behavior covered by tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100