Skip to content

Commit

Permalink
Lambda-free reference to instance method
Browse files Browse the repository at this point in the history
Amends 9cdd541, the fix for #1326.
  • Loading branch information
sampsyo committed Feb 14, 2015
1 parent 9cdd541 commit b80713c
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions beets/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,8 +420,7 @@ class Item(LibModel):
def _getters(cls):
getters = plugins.item_field_getters()
getters['singleton'] = lambda i: i.album_id is None
# Filesize is given in bytes
getters['filesize'] = lambda i: i.try_filesize()
getters['filesize'] = Item.try_filesize # In bytes.
return getters

@classmethod
Expand Down Expand Up @@ -606,6 +605,10 @@ def current_mtime(self):
return int(os.path.getmtime(syspath(self.path)))

def try_filesize(self):
"""Get the size of the underlying file in bytes.
If the file is missing, return 0 (and log a warning).
"""
try:
return os.path.getsize(syspath(self.path))
except (OSError, Exception) as exc:
Expand Down

0 comments on commit b80713c

Please sign in to comment.