Skip to content

Commit 5efd421

Browse files
authored
Change type() into isinstance() (#357)
1 parent 64772dc commit 5efd421

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

canopen/objectdictionary/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def export_od(od, dest:Union[str,TextIO,None]=None, doc_type:Optional[str]=None)
2929
"""
3030

3131
doctypes = {"eds", "dcf"}
32-
if type(dest) is str:
32+
if isinstance(dest, str):
3333
if doc_type is None:
3434
for t in doctypes:
3535
if dest.endswith(f".{t}"):

canopen/objectdictionary/eds.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -323,11 +323,11 @@ def export_dcf(od, dest=None, fileInfo={}):
323323

324324
def export_eds(od, dest=None, file_info={}, device_commisioning=False):
325325
def export_object(obj, eds):
326-
if type(obj) is objectdictionary.Variable:
326+
if isinstance(obj, objectdictionary.Variable):
327327
return export_variable(obj, eds)
328-
if type(obj) is objectdictionary.Record:
328+
if isinstance(obj, objectdictionary.Record):
329329
return export_record(obj, eds)
330-
if type(obj) is objectdictionary.Array:
330+
if isinstance(obj, objectdictionary.Array):
331331
return export_array(obj, eds)
332332

333333
def export_common(var, eds, section):
@@ -337,7 +337,7 @@ def export_common(var, eds, section):
337337
eds.set(section, "StorageLocation", var.storage_location)
338338

339339
def export_variable(var, eds):
340-
if type(var.parent) is objectdictionary.ObjectDictionary:
340+
if isinstance(var.parent, objectdictionary.ObjectDictionary):
341341
# top level variable
342342
section = "%04X" % var.index
343343
else:
@@ -376,7 +376,7 @@ def export_record(var, eds):
376376
section = "%04X" % var.index
377377
export_common(var, eds, section)
378378
eds.set(section, "SubNumber", "0x%X" % len(var.subindices))
379-
ot = RECORD if type(var) is objectdictionary.Record else ARR
379+
ot = RECORD if isinstance(var, objectdictionary.Record) else ARR
380380
eds.set(section, "ObjectType", "0x%X" % ot)
381381
for i in var:
382382
export_variable(var[i], eds)
@@ -428,11 +428,11 @@ def export_record(var, eds):
428428
("LSS_Supported", "LSS_supported"),
429429
]:
430430
val = getattr(od.device_information, odprop, None)
431-
if type(val) is None:
431+
if val is None:
432432
continue
433-
elif type(val) is str:
433+
elif isinstance(val, str):
434434
eds.set("DeviceInfo", eprop, val)
435-
elif type(val) in (int, bool):
435+
elif isinstance(val, (int, bool)):
436436
eds.set("DeviceInfo", eprop, int(val))
437437

438438
# we are also adding out of spec baudrates here.

test/test_eds.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def test_export_eds(self):
144144
self.assertEqual(type(actual_object), type(expected_object))
145145
self.assertEqual(actual_object.name, expected_object.name)
146146

147-
if type(actual_object) is canopen.objectdictionary.Variable:
147+
if isinstance(actual_object, canopen.objectdictionary.Variable):
148148
expected_vars = [expected_object]
149149
actual_vars = [actual_object]
150150
else:

0 commit comments

Comments
 (0)