Skip to content

traitlets Dict should support a strict keys mode #921

Description

@mpenning

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

Example of what should raise a TraitError

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}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions