From 5866fd70056e5ad2a60c340cc274ea1fc5db07e1 Mon Sep 17 00:00:00 2001 From: Yuhong Guo Date: Mon, 4 Mar 2019 16:40:04 +0800 Subject: [PATCH] Add type check in free and change Exception to TypeError (#4221) --- python/ray/internal/internal_api.py | 6 ++++++ python/ray/worker.py | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/python/ray/internal/internal_api.py b/python/ray/internal/internal_api.py index f91bd0f53..902728ec3 100644 --- a/python/ray/internal/internal_api.py +++ b/python/ray/internal/internal_api.py @@ -35,6 +35,12 @@ def free(object_ids, local_only=False): raise TypeError("free() expects a list of ObjectID, got {}".format( type(object_ids))) + # Make sure that the values are object IDs. + for object_id in object_ids: + if not isinstance(object_id, ray.ObjectID): + raise TypeError("Attempting to call `free` on the value {}, " + "which is not an ray.ObjectID.".format(object_id)) + worker.check_connected() with profiling.profile("ray.free"): if len(object_ids) == 0: diff --git a/python/ray/worker.py b/python/ray/worker.py index 5d4409d74..bcd4a681c 100644 --- a/python/ray/worker.py +++ b/python/ray/worker.py @@ -347,7 +347,7 @@ class Worker(object): """ # Make sure that the value is not an object ID. if isinstance(value, ObjectID): - raise Exception( + raise TypeError( "Calling 'put' on an ray.ObjectID is not allowed " "(similarly, returning an ray.ObjectID from a remote " "function is not allowed). If you really want to " @@ -470,7 +470,7 @@ class Worker(object): # Make sure that the values are object IDs. for object_id in object_ids: if not isinstance(object_id, ObjectID): - raise Exception( + raise TypeError( "Attempting to call `get` on the value {}, " "which is not an ray.ObjectID.".format(object_id)) # Do an initial fetch for remote objects. We divide the fetch into @@ -1800,7 +1800,7 @@ def connect(info, driver_id = DriverID(_random_string()) if not isinstance(driver_id, DriverID): - raise Exception("The type of given driver id must be DriverID.") + raise TypeError("The type of given driver id must be DriverID.") worker.worker_id = driver_id.binary()