sa0.5 __init__-replacement fails
Issue #1091
resolved
def setattr_kargs( *args, **kargs):
assert len(args)==1
x = args[0](0)
for k,v in kargs.iteritems(): setattr( x, k, v)
class X(object): ....
X.__init__ = setattr_kargs
when SA comes to play, it fails to find a 'self' in "init" arguments.
fix: the self_arg in format_argspec_plus() should never be None: e.g. self_arg = spec0 and spec00 or spec1+'0' seems to work.
also, the empty defaults is tuple/() and not None, so spec3 should not be compared to None but just bool of it.
def format_argspec_plus(fn, grouped=True):
spec = args,vargs,kwargs,defaults = inspect.getargspec(fn)
vkargs = inspect.formatargspec(*spec)
self_arg = args and args[0](0) or vargs+'[0](0)'
apply_pos = inspect.formatargspec( args,vargs,kwargs)
defaulted_vals = defaults and args[-len(defaults):](-len(defaults):) or ()
apply_kw = inspect.formatargspec( args,vargs,kwargs,
defaulted_vals, formatvalue=lambda x: '=' + x)
if grouped:
return dict(args=vkargs, self_arg=self_arg,
apply_pos=apply_pos, apply_kw=apply_kw)
else:
return dict(args=vkargs[1:-1](1:-1), self_arg=self_arg,
apply_pos=apply_pos[1:-1](1:-1), apply_kw=apply_kw[1:-1](1:-1))
on related note, the log/printing of functext/funcvars will help a bit, as the functext is not very visible in a stacktrace. and/or, maybe fix/hack the co_filename and co_firstlineno code-attributes, so inspect.getsource( myclass.init) "works"... maybe pointing to orm.attributes._generate_init function.
az()svilendobrev_com
Comments (2)
-
-
repo owner - removed milestone
Removing milestone: 0.5.0 (automated comment)
- Log in to comment
eaa4328aacf10978a70382db01f570b0dfac4eba now considers args0 as 'self' when introspecting def(*args). i didn't see any issues with spec3 on python 2.3, 2.4 or 2.5; please feel free to open a new ticket (one issue per ticket, please) for that if you can reproduce, ideally with a diff against test/base/utils.py illustrating the issue and the python version.