"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))):
+ coltype = args[0]
+ if callable(coltype):
+ coltype = args[0]()
+
+ if (isinstance(coltype, types.AbstractType) or
+ (isinstance(coltype, type) and
+ issubclass(coltype, types.AbstractType))):
if type_ is not None:
raise exc.ArgumentError(
"May not pass type_ positionally and as a keyword.")
def to_instance(typeobj):
if typeobj is None:
return NULLTYPE
- elif isinstance(typeobj, type):
+
+ try:
return typeobj()
- else:
+ except TypeError:
return typeobj
def adapt_type(typeobj, colspecs):
print res2
assert(res2==[(2, False)])
+class CallableTest(TestBase, AssertsExecutionResults):
+ def setUpAll(self):
+ global meta
+ meta = MetaData(testing.db)
+
+ def tearDownAll(self):
+ meta.drop_all()
+
+ def test_callable_as_arg(self):
+ from functools import partial
+ ucode = partial(Unicode, assert_unicode=None)
+
+ thing_table = Table('thing', meta,
+ Column('name', ucode, primary_key=True)
+ )
+
+ def test_callable_as_kwarg(self):
+ from functools import partial
+ ucode = partial(Unicode, assert_unicode=None)
+
+ thang_table = Table('thang', meta,
+ Column('name', type_=ucode, primary_key=True)
+ )
+
if __name__ == "__main__":
testenv.main()