From 53528741b2dc0139dd5b8bc46f912b069dc6e48e Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Fri, 28 Aug 2020 17:31:31 -0700 Subject: [PATCH] Assert exists before trying to calculate size; explicit elif. If you have a path that you expect to expect to be a file, it is confusing to see the traceback where it attempts to listdir because self.is_file failed and the else was to treat it as a dir. I prefer this explicit exists check, and explicit dir check. Yeah, potential for race conditions exists. --- voussoirkit/pathclass.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/voussoirkit/pathclass.py b/voussoirkit/pathclass.py index 7ace84f..ee2573c 100644 --- a/voussoirkit/pathclass.py +++ b/voussoirkit/pathclass.py @@ -248,9 +248,10 @@ class Path: @property def size(self): + self.assert_exists() if self.is_file: return os.path.getsize(self.absolute_path) - else: + elif self.is_dir: return sum(file.size for file in self.walk() if file.is_file) def spawn(self, path):