enable queries over computed attributes

This makes containment (field in obj) work with all attributes even though
other dict-like methods for iterating over the object don't expose computed
fields by default. I think this is the right compromise to avoid accidental
eager evaluation of computed fields.
This commit is contained in:
Adrian Sampson 2013-12-24 15:30:39 -08:00
parent b38812b452
commit 3e59c158ff
5 changed files with 23 additions and 7 deletions

View file

@ -12,7 +12,7 @@
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
__version__ = '1.3.2'
__version__ = '1.3.3'
__author__ = 'Adrian Sampson <adrian@radbox.org>'
import beets.library

View file

@ -360,9 +360,9 @@ class Model(object):
self._dirty.add(key)
def keys(self, computed=False):
"""Get the fixed, flexible, and plugin-provided field names for
this object. The `computed` parameter controls whether computed
(plugin-provided) fields are included in the key list.
"""Get a list of available field names for this object. The
`computed` parameter controls whether computed (plugin-provided)
fields are included in the key list.
"""
base_keys = list(self._fields) + self._values_flex.keys()
if computed:
@ -381,6 +381,7 @@ class Model(object):
def items(self):
"""Iterate over (key, value) pairs that this object contains.
Computed fields are not included.
"""
for key in self.keys():
yield key, self[key]
@ -397,7 +398,7 @@ class Model(object):
def __contains__(self, key):
"""Determine whether `key` is an attribute on this object.
"""
return key in self.keys()
return key in self.keys(True)
# Convenient attribute access.

View file

@ -1,6 +1,21 @@
Changelog
=========
1.3.3 (in development)
----------------------
Version 1.3.3 brings a set of internal changes to how fields work. The
consequences for all users are:
* Plugin-provided fields can now be used in queries. For example, if you use
the :doc:`/plugins/inline` to define a field called ``era``, you can now
filter your library based on that field by typing something like
``beet list era:goldenage``.
For developers, the short version of the story is that Item and Album objects
provide *uniform access* across fixed, flexible, and computed attributes.
1.3.2 (December 22, 2013)
-------------------------

View file

@ -13,7 +13,7 @@ project = u'beets'
copyright = u'2012, Adrian Sampson'
version = '1.3'
release = '1.3.2'
release = '1.3.3'
pygments_style = 'sphinx'

View file

@ -42,7 +42,7 @@ if 'sdist' in sys.argv:
shutil.copytree(os.path.join(docdir, '_build', 'man'), mandir)
setup(name='beets',
version='1.3.2',
version='1.3.3',
description='music tagger and library organizer',
author='Adrian Sampson',
author_email='adrian@radbox.org',