Skip to content

DictValidator: Allow non-string keys / customizable key validation #114

@binaryDiv

Description

@binaryDiv

Currently, the DictValidator only allows strings as dictionary keys.

Originally the reason for this was purely "we mostly want to use this with JSON and JSON doesn't support non-string keys anyway", but there are cases where non-string keys (e.g. integers) can be useful.

There are some open questions about this, though.

  • It could(?) still make sense to have optional data type validation for keys, or even more specific/custom validation by specifying an arbitrary Validator as key_validator.
  • If we allow key validators, it could be an option to have "light-weight" validation that only checks the type (so instead of specifying a Validator, just specify the type and the DictValidator will only do a isinstance check.
  • Do we allow field validators for arbitrary key types too? (I don't see why not, but it could have some unexpected effects on testing, for example.)
  • What should the default be? Allow any type, or keep the current behaviour (strings only) as the default?

Metadata

Metadata

Assignees

Labels

enhancementImprovements to existing features or smaller new featuresquestionFurther information is requested

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions