|
From: Michael F. <mi...@vo...> - 2008-01-16 09:36:20
|
Hello guys,
I'm looking at the problem that specifying a list type with validate can
let strings through unchanged.
The problem is simple enough - validate calls len on arguments and
assumes that anything with a length is a list!
try:
length = len(value)
except TypeError:
raise VdtTypeError(value)
The question is how to fix it. As strings are an odd sequence type, I
propose to add a specific 'isinstance(value, basestring)' check to catch
strings. I also propose to return list(value) as validate is supposed to
guarantee the return type of validated values.
A side effect of this is that tuples validated as lists will become
lists. If this is a problem I could add 'is_tuple' equivalents to the
'is_list' validate functions... (Differing not on what input they
accept, but only on the type of the returned value...)
Michael Foord
http://www.manning.com/foord
|