ipython / ipython/traitlets

traitlets Dict should support a strict keys mode

Open
#921 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
653
Forks
217
Avg merge
2d 21h
Merged PRs (30d)
2

Description

Please add support for a way to restrict keys on a `Dict`...

Example of what should raise a `TraitError`

```python
from traitlets import HasTraits, Dict, Unicode

class Foo(HasTraits):
# the strict_keys keyword is a suggested feature...
data = Dict(per_key_traits={"this_key": Unicode()}, strict_keys=True)

foo = Foo()

# This is fine...
foo.data = {"this_key": "value"}

# This should raise a TraitError
foo.data = {"invalid_key": None}
```

Contributor guide

Open the contributing guide

Research direction

Start by locating the Dict implementation and its handling of per_key_traits. Add coverage for the strict_keys example, including acceptance of declared keys and a TraitError for invalid keys; done means the requested behavior is tested and works.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.