Skip to content

Commit

Permalink
Add type check in free and change Exception to TypeError (ray-project…
Browse files Browse the repository at this point in the history
  • Loading branch information
guoyuhong authored Mar 4, 2019
1 parent e96e06e commit 5866fd7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 6 additions & 0 deletions python/ray/internal/internal_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions python/ray/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ def put_object(self, object_id, value):
"""
# 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 "
Expand Down Expand Up @@ -470,7 +470,7 @@ def get_object(self, object_ids):
# 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
Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit 5866fd7

Please sign in to comment.