Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion canopen/objectdictionary/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ def __getitem__(
self, index: Union[int, str]
) -> Union[ODArray, ODRecord, ODVariable]:
"""Get object from object dictionary by name or index."""
item = self.names.get(index) or self.indices.get(index)
item = self.names.get(index)
if item is None:
item = self.indices.get(index)
if item is None:
if isinstance(index, str) and '.' in index:
idx, sub = index.split('.', maxsplit=1)
Expand Down
12 changes: 12 additions & 0 deletions test/test_od.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,18 @@ def test_get_item_dot(self):
self.assertEqual(test_od["Test Array.Test Variable"], member1)
self.assertEqual(test_od["Test Array.Test Variable 2"], member2)

def test_get_item_index(self):
test_od = od.ObjectDictionary()
array = od.ODArray("Test Array", 0x1000)
test_od.add_object(array)
item = test_od[0x1000]
self.assertIsInstance(item, od.ODArray)
self.assertIs(item, array)
item = test_od["Test Array"]
self.assertIsInstance(item, od.ODArray)
self.assertIs(item, array)


class TestArray(unittest.TestCase):

def test_subindexes(self):
Expand Down
Loading