Convert formatting automatically to f-strings

Automatically convert formatting with the following call:
flynt -ll 2000 -v frappy*
Result: 303/381 auto-converted.
Failing conversions will be looked at manually in a follow-up commit.

Change-Id: Icd996b27221202faccc15af78e0380cf52ee37f2
Reviewed-on: https://forge.frm2.tum.de/review/c/secop/frappy/+/30900
Tested-by: Jenkins Automated Tests <pedersen+jenkins@frm2.tum.de>
Reviewed-by: Georg Brandl <g.brandl@fz-juelich.de>
Reviewed-by: Alexander Zaft <a.zaft@fz-juelich.de>
This commit is contained in:
Alexander Zaft
2023-04-14 07:12:03 +02:00
parent c114dbab26
commit 34183453e0
56 changed files with 327 additions and 380 deletions

View File

@@ -102,11 +102,11 @@ class GeneralConfig:
if cfg.get('confdir') is None:
cfg['confdir'] = path.dirname(configfile)
for key in mandatory:
cfg[key] = environ.get('FRAPPY_%s' % key.upper(), cfg.get(key))
cfg[key] = environ.get(f'FRAPPY_{key.upper()}', cfg.get(key))
missing_keys = [key for key in mandatory if cfg[key] is None]
if missing_keys:
if configfile:
raise KeyError('missing value for %s in %s' % (' and '.join(missing_keys), configfile))
raise KeyError(f"missing value for {' and '.join(missing_keys)} in {configfile}")
raise KeyError('missing %s' % ' and '.join('FRAPPY_%s' % k.upper() for k in missing_keys))
# this is not customizable
cfg['basedir'] = repodir
@@ -215,7 +215,7 @@ def get_class(spec):
def mkthread(func, *args, **kwds):
t = threading.Thread(
name='%s:%s' % (func.__module__, func.__name__),
name=f'{func.__module__}:{func.__name__}',
target=func,
args=args,
kwargs=kwds)
@@ -250,7 +250,7 @@ def formatExtendedTraceback(exc_info=None):
linecache.checkcache(filename)
line = linecache.getline(filename, tb.tb_lineno, frame.f_globals)
if line:
item = item + ' %s\n' % line.strip()
item = item + f' {line.strip()}\n'
ret.append(item)
if filename not in ('<script>', '<string>'):
ret += formatExtendedFrame(tb.tb_frame)
@@ -271,7 +271,7 @@ def formatExtendedStack(level=1):
linecache.checkcache(filename)
line = linecache.getline(filename, lineno, f.f_globals)
if line:
item = item + ' %s\n' % line.strip()
item = item + f' {line.strip()}\n'
ret.insert(1, item)
if filename != '<script>':
ret[2:2] = formatExtendedFrame(f)
@@ -317,10 +317,10 @@ def parseHostPort(host, defaultport):
else:
host, port = host
if not HOSTNAMEPAT.match(host):
raise ValueError('illegal host name %r' % host)
raise ValueError(f'illegal host name {host!r}')
if 0 < port < 65536:
return host, port
raise ValueError('illegal port number: %r' % port)
raise ValueError(f'illegal port number: {port!r}')
def tcpSocket(host, defaultport, timeout=None):