I’m talking about stuff like this: [
instead of the more verbose but maybe easier to grasp for python noobs: ]
for file in files:
file.unlink()
Maybe with a bit more context:
def _cleanup(self) -> None:
dirs, files = partition(lambda f: f.is_file(), self._tmp_dir.rglob("*"))
[file.unlink() for file in files]
[dir.rmdir() for dir in dirs]
self._tmp_dir.rmdir()
I don’t think this is a good place to use list comprehension. Yes the code is smaller, but it is very hacky. It’s like those flight booking hacks where you book for a different destination with your actual destination as a transit location. Yes it’s cheaper, but that’s not an elegant solution.