First, can you actually understand the final shape of the somejob string? For me it is just utterly cryptic. How many {} are there?
So, what is wrong with this case and how can we improve it?
The problem with this string formatting example is that constants are being passed as variables, hiding the shape of the string. It becomes much easier to read if the developer defines the constant sub-strings in the main string:
Still, because in this particular case we are using paths, I would go further and advocate for using pathlib.Path instead of the hardcoded /:
# reduce the long call to a short temporary variable_tmp = someobj.somemethod(run["run_dir"])somejob = Path( rundir,f'{fileroot}_{_tmp}_{somevar}w',)
I truly believe these modifications improve code reading and facilitates the life of maintainers. What do you think? Does the last example reads better than the first one?