alecthomas / voluptuous

CONTRIBUTIONS ONLY: Voluptuous, despite the name, is a Python data validation library.
https://pypi.org/project/voluptuous
BSD 3-Clause "New" or "Revised" License
1.82k stars 218 forks source link

More specific error message for Any() #412

Open Suor opened 4 years ago

Suor commented 4 years ago

Now it's:

from voluptuous import Any, Schema

schema = Schema(Any(str, None))
schema(10)
# MultipleInvalid: not a valid value

I would expect something like "expected str or none". I know I can pass msg to Any, but it would be nice to have better default for such a common case.

spacegaier commented 4 years ago

This error message however would quickly get quite long if there are more than only those two validators in the Any() clause, plus it would need some logic to generate proper language in a generic way, e.g. if there are then further validators such as Range, Contains or NotIn.