Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove f-strings #916

Merged
Merged
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
25 changes: 15 additions & 10 deletions qcodes/utils/magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
if sys.version_info < (3, 6):
raise RuntimeError('Magic only supported for Python version 3.6 and up')


@magics_class
class QCoDeSMagic(Magics):
"""Magics related to code management (loading, saving, editing, ...)."""
Expand Down Expand Up @@ -82,11 +83,10 @@ def measurement(self, line, cell=None):
data_name = options.get('d', 'data')
loop_name = options.get('l', 'loop')


lines = cell.splitlines()
assert lines[0][:3] == 'for', "Measurement must start with for loop"

contents = f'import qcodes\n{loop_name} = '
contents = 'import qcodes\n{} = '.format(loop_name)
previous_level = 0
for k, line in enumerate(lines):
line, level = line.lstrip(), int((len(line)-len(line.lstrip())) / 4)
Expand All @@ -99,7 +99,7 @@ def measurement(self, line, cell=None):
continue
else:
line_representation = ' ' * level * 4
if level < previous_level :
if level < previous_level:
# Exiting inner loop, close bracket
line_representation += '),' * (previous_level - level)
line_representation += '\n' + ' ' * level * 4
Expand All @@ -109,13 +109,16 @@ def measurement(self, line, cell=None):
for_opts, for_code = self.parse_options(line[4:-1], 'd:')
if 'd' in for_opts:
# Delay option provided
line_representation += f'qcodes.Loop({for_code}, ' \
f'delay={for_opts["d"]}).each(\n'
line_representation += ('qcodes.Loop({}, '
'delay={}).each(\n'
''.format(for_code,
for_opts["d"]))
else:
line_representation += f'qcodes.Loop({for_code}).each(\n'
line_representation += ('qcodes.Loop({}).each(\n'
''.format(for_code))
else:
# Action in current loop
line_representation += f'{line},\n'
line_representation += '{},\n'.format(line)
contents += line_representation

# Remember level for next iteration (might exit inner loop)
Expand All @@ -124,7 +127,9 @@ def measurement(self, line, cell=None):
# Add closing brackets for any remaining loops
contents += ')' * previous_level + '\n'
# Add dataset
contents += f"{data_name} = {loop_name}.get_data_set(name='{msmt_name}')"
contents += "{} = {}.get_data_set(name='{}')".format(data_name,
loop_name,
msmt_name)

for line in lines[k+1:]:
contents += '\n' + line
Expand Down Expand Up @@ -154,6 +159,6 @@ def register_magic_class(cls=QCoDeSMagic, magic_commands=True):
if magic_commands is not True:
# filter out any magic commands that are not in magic_commands
cls.magics = {line_cell: {key: val for key, val in magics.items()
if key in magic_commands}
if key in magic_commands}
for line_cell, magics in cls.magics.items()}
ip.magics_manager.register(cls)
ip.magics_manager.register(cls)