[Feature Request] Support `Checker([LIST_OF], LIST_OF=Optional[...])`
mattwang44 opened this issue · 1 comments
mattwang44 commented
Here is a minimum-reproducible code:
class _Spec:
data = Checker([LIST_OF], LIST_OF=Optional[str])
validate_data_spec({'data': ['str', None]}, _Spec)
# TypeError: field: _Spec.data, reason: ['str', None] is not a spec of <class '__main__._Spec'>, detail: AttributeError('find')
tried with str | None
class _Spec:
data = Checker([LIST_OF], LIST_OF=None | str)
validate_data_spec({'data': ['str', None]}, _Spec)
# TypeError: field: _Spec.data, reason: ['str', None] is not a spec of <class '__main__._Spec'>, detail: AttributeError("'types.UnionType' object has no attribute 'find'")
kilikkuo commented
I'm not a fan of returning a list of objects which contains different type of data.
But that is not the scope that DSV should consider about.
IMO, I prefer not mixed-using both DSV defined Checks (i.e. STR, NONE, SPEC,...) and Python typing object (i.e. Optional, Dic, Tuple, Any,...). As it could become a bottomless pit in terms of feature supporting,
For example,
Please support Optional
against Checker, make
class _Spec:
field = Checker([int], optional=True)
equals to
class _Spec:
field = Optional[Checker([int])]
Besides, the original idea of DSV is to support from python 2.7, it could be a complete different design when Python typing comes into play.
I guess we can start supporting something like
class _Spec:
data = Checker([LIST_OF], LIST_OF=[None, str, SPEC_A, SPEC_B])
idea ?