-
Notifications
You must be signed in to change notification settings - Fork 215
Open
Description
>>> schema = Schema({Optional('id'): Use(int), str: str})
>>> schema.validate({'id': '23', 'other': 'asf'})
>>> {'id': '23', 'other': 'asf'}
I think value of id should be converted to integer 23 instead of string '23'("by Use(int)").But "str: str" has a higher priority than "Optional('id')", so it just ignores the "Use(int)" statement.
I check the code about priority
def priority(s):
if type(s) in (list, tuple, set, frozenset):
return 6
if type(s) is dict:
return 5
if hasattr(s, 'validate'):
return 4
if type(s) is type:
return 3
if callable(s):
return 2
else:
return 1
Optional has a 'validate' attribute which is inherited from Schema class, so it return 4 here, higher than 3 of the str case.
Metadata
Metadata
Assignees
Labels
No labels