Skip to content

Commit 26d394a

Browse files
committed
Refactor.
1 parent 0130eb8 commit 26d394a

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

canopen/pdo/base.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,19 @@ def __iter__(self):
4040
return iter(self.map)
4141

4242
def __getitem__(self, key):
43-
if isinstance(key, int) and (0x1A00 <= key <= 0x1BFF or # By TPDO ID (512)
44-
0x1600 <= key <= 0x17FF or # By RPDO ID (512)
45-
0 < key <= 512): # By PDO Index
46-
return self.map[key]
47-
else:
48-
for pdo_map in self.map.values():
49-
try:
50-
return pdo_map[key]
51-
except KeyError:
52-
# ignore if one specific PDO does not have the key and try the next one
53-
continue
43+
if isinstance(key, int):
44+
if (
45+
0 < key <= 512 # By PDO Index
46+
or 0x1600 <= key <= 0x17FF # By RPDO ID (512)
47+
or 0x1A00 <= key <= 0x1BFF # By TPDO ID (512)
48+
):
49+
return self.map[key]
50+
for pdo_map in self.map.values():
51+
try:
52+
return pdo_map[key]
53+
except KeyError:
54+
# ignore if one specific PDO does not have the key and try the next one
55+
continue
5456
raise KeyError(f"PDO: {key} was not found in any map")
5557

5658
def __len__(self):

0 commit comments

Comments
 (0)