Favor the simplest, most idiomatic construct that accomplishes the task, and remove any code that doesn’t add value. Concretely:
if, which reduces indentation and improves readability:
# instead of
def sigint_handler(self, signum, frame):
if not self.nosigint:
... # rest of the body nested here
# prefer
def sigint_handler(self, signum, frame):
if self.nosigint:
return
...
pathlib.Path for filesystem setup instead of chaining os.path.join/os.mkdir/open(...).write(...), and use functools.partial instead of repeating near-identical lambdas.bool(...), or using is where == is intended for value comparison.sum(1 for ... )) is just as clear; only factor out code when it genuinely improves clarity or is reused.Applying these checks during review keeps the codebase concise, reduces cognitive load, and prevents small stylistic inconsistencies from accumulating.