Skip to content

Commit 11a8f91

Browse files
author
Brandon Palm
committed
Use instanceof instead of type
Adjusted conditional statements to use instanceof when comparing variables. Instanceof supports inheritance type checking better than type. Change-Id: I4ee0004934dc2322d43ef07e797a6811e39a812c Closes-Bug: 1548530
1 parent c57fc41 commit 11a8f91

3 files changed

Lines changed: 6 additions & 6 deletions

File tree

openstackclient/api/api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,14 +243,14 @@ def find_attr(
243243
def getlist(kw):
244244
"""Do list call, unwrap resource dict if present"""
245245
ret = self.list(path, **kw)
246-
if type(ret) == dict and resource in ret:
246+
if isinstance(ret, dict) and resource in ret:
247247
ret = ret[resource]
248248
return ret
249249

250250
# Search by attribute
251251
kwargs = {attr: value}
252252
data = getlist(kwargs)
253-
if type(data) == dict:
253+
if isinstance(data, dict):
254254
return data
255255
if len(data) == 1:
256256
return data[0]
@@ -283,7 +283,7 @@ def find_bulk(
283283
"""
284284

285285
items = self.list(path)
286-
if type(items) == dict:
286+
if isinstance(items, dict):
287287
# strip off the enclosing dict
288288
key = list(items.keys())[0]
289289
items = items[key]

openstackclient/api/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def simple_filter(
6161
# Searching data fields
6262
search_value = d[attr]
6363
elif (property_field and property_field in d and
64-
type(d[property_field]) is dict):
64+
isinstance(d[property_field], dict)):
6565
# Searching a properties field - do this separately because
6666
# we don't want to fail over to checking the fields if a
6767
# property name is given.

openstackclient/tests/test_shell.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ def _test_options_init_app(self, test_opts):
317317
if not test_opts[opt][1]:
318318
continue
319319
key = opt2attr(opt)
320-
if type(test_opts[opt][0]) is str:
320+
if isinstance(test_opts[opt][0], str):
321321
cmd = opt + " " + test_opts[opt][0]
322322
else:
323323
cmd = opt
@@ -331,7 +331,7 @@ def _test_options_get_one_cloud(self, test_opts):
331331
if not test_opts[opt][1]:
332332
continue
333333
key = opt2attr(opt)
334-
if type(test_opts[opt][0]) is str:
334+
if isinstance(test_opts[opt][0], str):
335335
cmd = opt + " " + test_opts[opt][0]
336336
else:
337337
cmd = opt

0 commit comments

Comments
 (0)