From 64b4cba67c98ff82ca1505b410665b3609ea22a4 Mon Sep 17 00:00:00 2001 From: Markus Zolliker Date: Thu, 20 Apr 2023 15:33:44 +0200 Subject: [PATCH] fix error from manual %-format conversion frappy_psi.ppms (line 263) was not correctly converted probably due to the fact, that dict access with f-strings gets quite ugly. As it seems we want to get rid of %-format, use str.format_map here. Change-Id: Idf5b700554aa7a02a6647dc4672bf4a3856f92a5 Reviewed-on: https://forge.frm2.tum.de/review/c/secop/frappy/+/30933 Tested-by: Jenkins Automated Tests Reviewed-by: Alexander Zaft Reviewed-by: Markus Zolliker --- frappy_psi/ls370res.py | 10 ++++------ frappy_psi/ppms.py | 7 +++---- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/frappy_psi/ls370res.py b/frappy_psi/ls370res.py index 906846a..04cdea0 100644 --- a/frappy_psi/ls370res.py +++ b/frappy_psi/ls370res.py @@ -267,8 +267,7 @@ class ResChannel(Channel): if self.autorange: if rng < self.minrange: rng = self.minrange - self.communicate('RDGRNG %d,%d,%d,%d,%d,%d;*OPC?' % ( - self.channel, iscur, exc, rng, 0, excoff)) + self.communicate(f'RDGRNG {self.channel},{iscur},{exc},{rng},0,{excoff};*OPC?') self.read_range() def fix_autorange(self): @@ -290,12 +289,11 @@ class ResChannel(Channel): @CommonWriteHandler(inset_params) def write_inset(self, change): - _, _, _, curve, tempco = literal_eval( + _, _, _, change['curve'], change['tempco'] = literal_eval( self.communicate(f'INSET?{self.channel}')) self.enabled, self.dwell, self.pause, _, _ = literal_eval( - self.communicate('INSET %d,%d,%d,%d,%d,%d;INSET?%d' % ( - self.channel, change['enabled'], change['dwell'], change['pause'], curve, tempco, - self.channel))) + self.communicate('INSET {channel},{enabled:d},{dwell:d},' + '{pause:d},{curve},{tempco};INSET?{channel}'.format_map(change))) if 'enabled' in change and change['enabled']: # switch to enabled channel self.switcher.write_target(self.channel) diff --git a/frappy_psi/ppms.py b/frappy_psi/ppms.py index 697ae30..abb64b0 100644 --- a/frappy_psi/ppms.py +++ b/frappy_psi/ppms.py @@ -215,7 +215,7 @@ class DriverChannel(Channel): :param values: a dict like object containing the parameters to be written """ self.read_params() # make sure parameters are up to date - self.comm_write(f"DRVOUT {values['no']},{values['current']:g},{values['powerlimit']:g}") + self.comm_write('DRVOUT {no:d},{current:g},{powerlimit:g}'.format_map(values)) self.read_params() # read back @@ -260,9 +260,8 @@ class BridgeChannel(Channel): values['excitation'] = 0 values['powerlimit'] = 0 values['voltagelimit'] = 0 - self.comm_write(f"BRIDGE {values['no']},{values['enabled']:g},' \ - f'{values['powerlimit']:g},{int(values['dcflag'])},{int(values['readingmode'])},' \ - f'{values['voltagelimit']:g}") + self.comm_write('BRIDGE {no:d},{enabled:d},{powerlimit:g},{dcflag:d},' + '{readingmode:d},{voltagelimit:g}'.format_map(values)) self.read_params() # read back