Commit c3ba9069 authored by Vincent Pelletier's avatar Vincent Pelletier

ZSQLCatalog: Do not distinguish between int, long and floats in lists.

Do not require caller to cast between these types when they can all make
sense to appear in the same list.
parent 03d737fc
...@@ -73,6 +73,8 @@ operator_value_deprocessor_dict = { ...@@ -73,6 +73,8 @@ operator_value_deprocessor_dict = {
'like': deprocessLikeValue 'like': deprocessLikeValue
} }
numeric_type_set = (long, float) # get mapped to int, so do not mention it
class SearchKey(object): class SearchKey(object):
implements(ISearchKey) implements(ISearchKey)
...@@ -266,16 +268,21 @@ class SearchKey(object): ...@@ -266,16 +268,21 @@ class SearchKey(object):
# Cast to list # Cast to list
if isinstance(search_value, list_type_list): if isinstance(search_value, list_type_list):
# Check list content (not empty, homogenous) # Check list content (not empty, homogenous)
iter_search_value = iter(search_value) # Note: neither is strictly required, but it helps spotting easy mistakes.
klass_set = {
int if x.__class__ in numeric_type_set else x.__class__
for x in search_value
}
try: try:
reference_class = iter_search_value.next().__class__ reference_class, = klass_set
except StopIteration: except ValueError:
raise ValueError, 'Value cannot be an empty list/tuple: %r' % \ if search_value:
(search_value, ) raise TypeError(
for x in iter_search_value: 'List elements must be of the same class: %r' % (search_value, )
if x.__class__ != reference_class: )
raise TypeError, 'List elements must be of the same class: %r' % \ raise ValueError(
(search_value, ) 'Value cannot be an empty list/tuple: %r' % (search_value, )
)
else: else:
assert logical_operator is None assert logical_operator is None
if isinstance(search_value, dict): if isinstance(search_value, dict):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment