@@ -377,10 +377,7 @@ def RemoveSubentriesFromCurrent(self, index: int, number: int):
377
377
length = node .GetEntry (index , 0 )
378
378
# FIXME: This code assumes that subindex 0 is the length of the entry
379
379
assert isinstance (length , int )
380
- if "nbmin" in infos :
381
- nbmin = infos ["nbmin" ]
382
- else :
383
- nbmin = 1
380
+ nbmin = infos .get ("nbmin" , 1 )
384
381
# Entry is an array, or is an array/record of manufacturer specific
385
382
# FIXME: What is the intended order of the conditions? or-and on same level
386
383
if (infos ["struct" ] & OD .IdenticalSubindexes or 0x2000 <= index <= 0x5FFF
@@ -574,7 +571,7 @@ def RemoveCurrentVariable(self, index: int, subindex: int|None = None):
574
571
node .RemoveMapVariable (index , subindex or 0 )
575
572
if not found :
576
573
infos = node .GetEntryInfos (index )
577
- if not infos [ "need" ] :
574
+ if not infos . get ( "need" ) :
578
575
node .RemoveEntry (index , subindex )
579
576
if index in mappings [- 1 ]:
580
577
node .RemoveMappingEntry (index , subindex )
@@ -700,8 +697,7 @@ def SetCurrentEntry(self, index: int, subindex: int, value: str, name: str, edit
700
697
# Might fail with binascii.Error if hex is malformed
701
698
if len (value ) % 2 != 0 :
702
699
value = "0" + value
703
- # FIXME: decode() produce bytes, which is not supported as of now
704
- bvalue = codecs .decode (value , 'hex_codec' )
700
+ bvalue = codecs .decode (value , 'hex_codec' ).decode ()
705
701
node .SetEntry (index , subindex , bvalue )
706
702
elif editor == "dcf" :
707
703
node .SetEntry (index , subindex , value )
@@ -737,12 +733,14 @@ def SetCurrentEntry(self, index: int, subindex: int, value: str, name: str, edit
737
733
raise ValueError ("Number must be positive" )
738
734
node .SetParamsEntry (index , subindex , params = {"buffer_size" : nvalue })
739
735
else :
736
+ nvalue : str | int = value
740
737
if editor == "type" :
741
738
nvalue = node .GetTypeIndex (value )
739
+ # All type object shall have size
742
740
size = node .GetEntryInfos (nvalue )["size" ]
743
741
node .UpdateMapVariable (index , subindex , size )
744
742
elif editor in ["access" , "raccess" ]:
745
- value = {
743
+ nvalue = { # type: ignore[assignment]
746
744
access : abbrev
747
745
for abbrev , access in maps .ACCESS_TYPE .items ()
748
746
}[value ]
@@ -753,7 +751,7 @@ def SetCurrentEntry(self, index: int, subindex: int, value: str, name: str, edit
753
751
node .AddMappingEntry (index , entry = {"name" : entry_infos ["name" ], "struct" : OD .ARRAY })
754
752
node .AddMappingSubEntry (index , 0 , values = subindex0_infos )
755
753
node .AddMappingSubEntry (index , 1 , values = subindex1_infos )
756
- node .SetMappingSubEntry (index , subindex , values = {name : value }) # type: ignore[misc]
754
+ node .SetMappingSubEntry (index , subindex , values = {name : nvalue }) # type: ignore[misc]
757
755
if not disable_buffer :
758
756
self .BufferCurrentNode ()
759
757
@@ -1049,7 +1047,7 @@ def GetNodeEntryValues(self, node: Node, index: int) -> tuple[list[dict], list[d
1049
1047
editor ["value" ] = "dcf"
1050
1048
else :
1051
1049
editor ["value" ] = "domain"
1052
- dic ["value" ] = codecs .encode (dic ["value" ].encode (), 'hex_codec' )
1050
+ dic ["value" ] = codecs .encode (dic ["value" ].encode (), 'hex_codec' ). decode ()
1053
1051
elif dic ["type" ] == "BOOLEAN" :
1054
1052
editor ["value" ] = "bool"
1055
1053
dic ["value" ] = maps .BOOL_TYPE [dic ["value" ]]
@@ -1065,7 +1063,7 @@ def GetNodeEntryValues(self, node: Node, index: int) -> tuple[list[dict], list[d
1065
1063
raise # FIXME: Originial code swallows exception
1066
1064
try :
1067
1065
dic ["value" ] = fmt .format (dic ["value" ])
1068
- except TypeError as exc :
1066
+ except ValueError as exc :
1069
1067
log .debug ("ValueError: '%s': %s" , dic ["value" ], exc )
1070
1068
# FIXME: dict["value"] can contain $NODEID for PDOs i.e. $NODEID+0x200
1071
1069
editor ["value" ] = "string"
0 commit comments