Validation of empty lists
Closed this issue · 5 comments
type_matches([], 'List[T]')
is true for any underlying type T
. Should type_matches
throw on empty lists?
For me it is fine if that function returns True
.
If we do not allow empty lists, I think this should be caught one level up.
Turns out tests for the grammar were not looking at this edge case.
Somewhat related:
At least in the getkw grammar, an input list with a single entry of type T
is translated to a raw type T
in the processed JSON, e.i.
double_array = [1.0]
translates into
{
"double_array" : 1.0
}
This behavior is not wanted if you have lists of unknown size.
Dang! Not good, not good at all. I'll add tests and see how this can be fixed.
I have asked a question on StackOverflow, because all my attempts at raising meaningful exceptions on empty lists have been unsuccessful. Here is the question, which also includes an example: https://stackoverflow.com/questions/55187629/pyparsing-raise-exception-on-emtpy-delimitedlist