Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Support Checker([LIST_OF], LIST_OF=Optional[...]) #39

Open
mattwang44 opened this issue Jun 2, 2023 · 1 comment
Open

Comments

@mattwang44
Copy link
Member

mattwang44 commented Jun 2, 2023

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
Copy link
Contributor

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 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants