From 1cdb30fd560cb5b47f1c140d6180e18af46f6b5f Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Mon, 20 Jan 2014 18:06:42 -0800 Subject: [PATCH] remove superfluous py_type field from Type --- beets/dbcore/db.py | 6 +++--- beets/library.py | 17 ++++++++--------- test/test_dbcore.py | 4 ++-- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/beets/dbcore/db.py b/beets/dbcore/db.py index 3865034c5..4ba73617f 100644 --- a/beets/dbcore/db.py +++ b/beets/dbcore/db.py @@ -66,7 +66,7 @@ def format_for_path(value, key=None): # Abstract base for model classes and their field types. -Type = namedtuple('Type', 'py_type sql_type query') +Type = namedtuple('Type', 'sql query') class Model(object): @@ -637,7 +637,7 @@ class Database(object): # No table exists. columns = [] for name, typ in fields.items(): - columns.append('{0} {1}'.format(name, typ.sql_type)) + columns.append('{0} {1}'.format(name, typ.sql)) setup_sql = 'CREATE TABLE {0} ({1});\n'.format(table, ', '.join(columns)) @@ -648,7 +648,7 @@ class Database(object): if name in current_fields: continue setup_sql += 'ALTER TABLE {0} ADD COLUMN {1} {2};\n'.format( - table, name, typ.sql_type + table, name, typ.sql ) with self.transaction() as tx: diff --git a/beets/library.py b/beets/library.py index 95eaa4efc..569d7d2b5 100644 --- a/beets/library.py +++ b/beets/library.py @@ -79,13 +79,13 @@ class SingletonQuery(dbcore.Query): # Common types used in field definitions. TYPES = { - int: Type(int, 'INTEGER', dbcore.query.NumericQuery), - float: Type(float, 'REAL', dbcore.query.NumericQuery), - datetime: Type(datetime, 'REAL', dbcore.query.NumericQuery), - unicode: Type(unicode, 'TEXT', dbcore.query.SubstringQuery), - bool: Type(bool, 'INTEGER', dbcore.query.BooleanQuery), + int: Type('INTEGER', dbcore.query.NumericQuery), + float: Type('REAL', dbcore.query.NumericQuery), + datetime: Type('REAL', dbcore.query.NumericQuery), + unicode: Type('TEXT', dbcore.query.SubstringQuery), + bool: Type('INTEGER', dbcore.query.BooleanQuery), } -PATH_TYPE = Type(bytes, 'BLOB', PathQuery) +PATH_TYPE = Type('BLOB', PathQuery) # Fields in the "items" database table; all the metadata available for # items in the library. These are used directly in SQL; they are @@ -96,7 +96,7 @@ PATH_TYPE = Type(bytes, 'BLOB', PathQuery) # - Is the field writable? # - Does the field reflect an attribute of a MediaFile? ITEM_FIELDS = [ - ('id', Type(int, 'INTEGER PRIMARY KEY', dbcore.query.NumericQuery), + ('id', Type('INTEGER PRIMARY KEY', dbcore.query.NumericQuery), False, False), ('path', PATH_TYPE, False, False), ('album_id', TYPES[int], False, False), @@ -167,8 +167,7 @@ ITEM_KEYS = [f[0] for f in ITEM_FIELDS] # The third entry in each tuple indicates whether the field reflects an # identically-named field in the items table. ALBUM_FIELDS = [ - ('id', Type(int, 'INTEGER PRIMARY KEY', dbcore.query.NumericQuery), - False), + ('id', Type('INTEGER PRIMARY KEY', dbcore.query.NumericQuery), False), ('artpath', PATH_TYPE, False), ('added', TYPES[datetime], True), diff --git a/test/test_dbcore.py b/test/test_dbcore.py index e5ea4ead9..ff640800b 100644 --- a/test/test_dbcore.py +++ b/test/test_dbcore.py @@ -25,8 +25,8 @@ from beets import dbcore # Fixture: concrete database and model classes. For migration tests, we # have multiple models with different numbers of fields. -ID_TYPE = dbcore.Type(int, 'INTEGER PRIMARY KEY', dbcore.query.NumericQuery) -INT_TYPE = dbcore.Type(int, 'INTEGER', dbcore.query.NumericQuery) +ID_TYPE = dbcore.Type('INTEGER PRIMARY KEY', dbcore.query.NumericQuery) +INT_TYPE = dbcore.Type('INTEGER', dbcore.query.NumericQuery) class TestModel1(dbcore.Model): _table = 'test'