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:
parent
8e7eeb9c3f
commit
53528741b2
1 changed files with 2 additions and 1 deletions
|
@ -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):
|
||||
|
|
Loading…
Reference in a new issue