Skip to content

Why error value can be string and list of strings? #210

Description

@andreymal

It is uncomfortable for me. I have to write extra type checking.

This is OK (except #209, but it is not about that):

>>> v = Validator({'name': {'type': 'string', 'minlength': 6, 'regex': '[A-z]+'}})
>>> v.validate({'name': '©'})
False
>>> for field, value in v.errors.items():
...  print(field)
...  for error in value:
...   print(' -', error)
... 
name
 - max length is 6
 - value does not match regex '[A-z]+'

But:

>>> v.validate({'name': 'abc'})
False
>>> for field, value in v.errors.items():
...  print(field)
...  for error in value:
...   print(' -', error)
... 
name
 - m
 - a
 - x
 -  
 - l
 - e
 - n
 - g
 - t
 - h
 -  
 - i
 - s
 -  
 - 6

WAT

I don't wish write if isinstance(value, str)!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions