diff options
| author | Jason Kirtland <jek@discorporate.us> | 2008-03-18 00:15:34 +0000 |
|---|---|---|
| committer | Jason Kirtland <jek@discorporate.us> | 2008-03-18 00:15:34 +0000 |
| commit | f979c19841e6803099827d58d4de65964391be49 (patch) | |
| tree | 3cb2ecae12a46c4c3329dae870f40c61c82f3d4c /lib/sqlalchemy/schema.py | |
| parent | 22197ca9c51173300450902887f8e6f8b9680007 (diff) | |
| download | sqlalchemy-f979c19841e6803099827d58d4de65964391be49.tar.gz | |
- 'name' is no longer a require constructor argument for Column(). It (and .key) may now be deferred until the Column is added to a Table.
Diffstat (limited to 'lib/sqlalchemy/schema.py')
| -rw-r--r-- | lib/sqlalchemy/schema.py | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/lib/sqlalchemy/schema.py b/lib/sqlalchemy/schema.py index 8d0b3d26d..c3db8bfad 100644 --- a/lib/sqlalchemy/schema.py +++ b/lib/sqlalchemy/schema.py @@ -405,7 +405,7 @@ class Column(SchemaItem, expression._ColumnClause): ``TableClause``/``Table``. """ - def __init__(self, name, type_, *args, **kwargs): + def __init__(self, *args, **kwargs): """Construct a new ``Column`` object. Arguments are: @@ -497,6 +497,24 @@ class Column(SchemaItem, expression._ColumnClause): auto-detect conditions where quoting is required. """ + name = kwargs.pop('name', None) + type_ = kwargs.pop('type_', None) + if args: + args = list(args) + if isinstance(args[0], basestring): + if name is not None: + raise exceptions.ArgumentError( + "May not pass name positionally and as a keyword.") + name = args.pop(0) + if args: + if (isinstance(args[0], types.AbstractType) or + (isinstance(args[0], type) and + issubclass(args[0], types.AbstractType))): + if type_ is not None: + raise exceptions.ArgumentError( + "May not pass type_ positionally and as a keyword.") + type_ = args.pop(0) + super(Column, self).__init__(name, None, type_) self.args = args self.key = kwargs.pop('key', name) @@ -561,6 +579,10 @@ class Column(SchemaItem, expression._ColumnClause): ["%s=%s" % (k, repr(getattr(self, k))) for k in kwarg]) def _set_parent(self, table): + if self.name is None: + raise exceptions.ArgumentError( + "Column must be constructed with a name or assign .name " + "before adding to a Table.") self.metadata = table.metadata if getattr(self, 'table', None) is not None: raise exceptions.ArgumentError("this Column already has a table!") |
