mirror of
https://github.com/wassname/catalyst.git
synced 2026-08-13 12:00:16 +08:00
Merge pull request #1734 from quantopian/prepare-for-validity-checks
MAINT: Prepare parameter check for adding an additional check.
This commit is contained in:
+24
-32
@@ -82,48 +82,40 @@ cdef class check_parameters(object):
|
|||||||
for i, arg in enumerate(args[1:]):
|
for i, arg in enumerate(args[1:]):
|
||||||
expected_type = self.types[i]
|
expected_type = self.types[i]
|
||||||
|
|
||||||
if isinstance(arg, expected_type):
|
if (i == 0 or i == 1) and _is_iterable(arg):
|
||||||
continue
|
|
||||||
|
|
||||||
elif (i == 0 or i == 1) and _is_iterable(arg):
|
|
||||||
if len(arg) == 0:
|
if len(arg) == 0:
|
||||||
continue
|
continue
|
||||||
|
arg = arg[0]
|
||||||
|
|
||||||
if isinstance(arg[0], expected_type):
|
if not isinstance(arg, expected_type):
|
||||||
continue
|
expected_type_name = expected_type.__name__ \
|
||||||
|
if not _is_iterable(expected_type) \
|
||||||
|
else ', '.join([type_.__name__ for type_ in expected_type])
|
||||||
|
|
||||||
expected_type_name = expected_type.__name__ \
|
raise TypeError("Expected %s argument to be of type %s%s" %
|
||||||
if not _is_iterable(expected_type) \
|
(self.keyword_names[i],
|
||||||
else ', '.join([type_.__name__ for type_ in expected_type])
|
'or iterable of type ' if i in (0, 1) else '',
|
||||||
|
expected_type_name)
|
||||||
raise TypeError("Expected %s argument to be of type %s%s" %
|
)
|
||||||
(self.keyword_names[i],
|
|
||||||
'or iterable of type ' if i in (0, 1) else '',
|
|
||||||
expected_type_name)
|
|
||||||
)
|
|
||||||
|
|
||||||
# verify type of each kwarg
|
# verify type of each kwarg
|
||||||
for keyword, arg in iteritems(kwargs):
|
for keyword, arg in iteritems(kwargs):
|
||||||
if isinstance(arg, self.keys_to_types[keyword]):
|
if keyword in ('assets', 'fields') and _is_iterable(arg):
|
||||||
continue
|
|
||||||
elif keyword in ('assets', 'fields') and _is_iterable(arg):
|
|
||||||
if len(arg) == 0:
|
if len(arg) == 0:
|
||||||
continue
|
continue
|
||||||
|
arg = arg[0]
|
||||||
|
if not isinstance(arg, self.keys_to_types[keyword]):
|
||||||
|
expected_type = self.keys_to_types[keyword].__name__ \
|
||||||
|
if not _is_iterable(self.keys_to_types[keyword]) \
|
||||||
|
else ', '.join([type_.__name__ for type_ in
|
||||||
|
self.keys_to_types[keyword]])
|
||||||
|
|
||||||
if isinstance(arg[0], self.keys_to_types[keyword]):
|
raise TypeError("Expected %s argument to be of type %s%s" %
|
||||||
continue
|
(keyword,
|
||||||
|
'or iterable of type ' if keyword in
|
||||||
expected_type = self.keys_to_types[keyword].__name__ \
|
('assets', 'fields') else '',
|
||||||
if not _is_iterable(self.keys_to_types[keyword]) \
|
expected_type)
|
||||||
else ', '.join([type_.__name__ for type_ in
|
)
|
||||||
self.keys_to_types[keyword]])
|
|
||||||
|
|
||||||
raise TypeError("Expected %s argument to be of type %s%s" %
|
|
||||||
(keyword,
|
|
||||||
'or iterable of type ' if keyword in
|
|
||||||
('assets', 'fields') else '',
|
|
||||||
expected_type)
|
|
||||||
)
|
|
||||||
|
|
||||||
return func(*args, **kwargs)
|
return func(*args, **kwargs)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user