int and long should be treated similarly (#220)

This commit is contained in:
mehrdadn
2016-07-07 03:31:58 +03:00
committed by Philipp Moritz
parent 5412d3c773
commit 199b4efd50
5 changed files with 35 additions and 5 deletions
+3
View File
@@ -11,6 +11,9 @@ import ray
class Int(int):
pass
class Long(long):
pass
class Float(float):
pass
+15 -4
View File
@@ -70,6 +70,8 @@ class Worker(object):
result = serialization.deserialize(self.handle, object_capsule)
if isinstance(result, int):
result = serialization.Int(result)
elif isinstance(result, long):
result = serialization.Long(result)
elif isinstance(result, float):
result = serialization.Float(result)
elif isinstance(result, bool):
@@ -396,6 +398,17 @@ def check_return_values(function, result):
if (not issubclass(type(result[i]), function.return_types[i])) and (not isinstance(result[i], ray.lib.ObjRef)):
raise Exception("The {}th return value for function {} has type {}, but the @remote decorator expected a return value of type {} or an ObjRef.".format(i, function.__name__, type(result[i]), function.return_types[i]))
def typecheck_arg(arg, expected_type, i, function):
if issubclass(type(arg), expected_type):
# Passed the type-checck
# TODO(rkn): This check doesn't really work, e.g., issubclass(type([1, 2, 3]), typing.List[str]) == True
pass
elif isinstance(arg, long) and issubclass(int, expected_type):
# TODO(mehrdadn): Should long really be convertible to int?
pass
else:
raise Exception("Argument {} for function {} has type {} but an argument of type {} was expected.".format(i, function.__name__, type(arg), expected_type))
# helper method, this should not be called by the user
def check_arguments(function, args):
# check the number of args
@@ -416,8 +429,7 @@ def check_arguments(function, args):
# TODO(rkn): When we have type information in the ObjRef, do type checking here.
pass
else:
if not issubclass(type(arg), expected_type): # TODO(rkn): This check doesn't really work, e.g., issubclass(type([1, 2, 3]), typing.List[str]) == True
raise Exception("Argument {} for function {} has type {} but an argument of type {} was expected.".format(i, function.__name__, type(arg), expected_type))
typecheck_arg(arg, expected_type, i, function)
# helper method, this should not be called by the user
def get_arguments_for_execution(function, args, worker=global_worker):
@@ -448,8 +460,7 @@ def get_arguments_for_execution(function, args, worker=global_worker):
# pass the argument by value
argument = arg
if not issubclass(type(argument), expected_type):
raise Exception("Argument {} for function {} has type {} but an argument of type {} was expected.".format(i, function.__name__, type(argument), expected_type))
typecheck_arg(argument, expected_type, i, function)
arguments.append(argument)
return arguments