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.
This commit is contained in:
Ethan Dalool 2020-08-28 17:31:31 -07:00
parent 8e7eeb9c3f
commit 53528741b2

View file

@ -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):