diff options
-rw-r--r-- | lib/sqlalchemy/util.py | 40 |
1 files changed, 0 insertions, 40 deletions
diff --git a/lib/sqlalchemy/util.py b/lib/sqlalchemy/util.py index bd40039d4..a4370edaf 100644 --- a/lib/sqlalchemy/util.py +++ b/lib/sqlalchemy/util.py @@ -259,43 +259,3 @@ class ScopedRegistry(object): return self.scopefunc() -def constructor_args(instance, **kwargs): - """given an object instance and keyword arguments, inspects the - argument signature of the instance's __init__ method and returns - a tuple of list and keyword arguments, suitable for creating a new - instance of the class. The returned arguments are drawn from the - given keyword dictionary, or if not found are drawn from the - corresponding attributes of the original instance.""" - classobj = instance.__class__ - - argspec = inspect.getargspec(classobj.__init__.im_func) - - argnames = argspec[0] or [] - defaultvalues = argspec[3] or [] - - (requiredargs, namedargs) = ( - argnames[0:len(argnames) - len(defaultvalues)], - argnames[len(argnames) - len(defaultvalues):] - ) - - newparams = {} - - for arg in requiredargs: - if arg == 'self': - continue - elif kwargs.has_key(arg): - newparams[arg] = kwargs[arg] - else: - newparams[arg] = getattr(instance, arg) - - for arg in namedargs: - if kwargs.has_key(arg): - newparams[arg] = kwargs[arg] - else: - if hasattr(instance, arg): - newparams[arg] = getattr(instance, arg) - else: - raise AssertionError("instance has no attribute '%s'" % arg) - - return newparams - |