]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- consider args[0] as self when introspecting def(*args): ... [ticket:1091]
authorJason Kirtland <jek@discorporate.us>
Sun, 29 Jun 2008 18:58:11 +0000 (18:58 +0000)
committerJason Kirtland <jek@discorporate.us>
Sun, 29 Jun 2008 18:58:11 +0000 (18:58 +0000)
lib/sqlalchemy/util.py
test/base/utils.py

index e0bf45b673d20d830571308a0d00fbe75413da26..dea3207244f7773fa0768efee32de3aaf103fb1c 100644 (file)
@@ -345,7 +345,8 @@ def format_argspec_plus(fn, grouped=True):
     args
       Full inspect.formatargspec for fn
     self_arg
-      The name of the first positional argument, or None
+      The name of the first positional argument, varargs[0], or None
+      if the function defines no positional arguments.
     apply_pos
       args, re-written in calling rather than receiving syntax.  Arguments are
       passed positionally.
@@ -363,7 +364,12 @@ def format_argspec_plus(fn, grouped=True):
     """
     spec = inspect.getargspec(fn)
     args = inspect.formatargspec(*spec)
-    self_arg = spec[0] and spec[0][0] or None
+    if spec[0]:
+        self_arg = spec[0][0]
+    elif spec[1]:
+        self_arg = '%s[0]' % spec[1]
+    else:
+        self_arg = None
     apply_pos = inspect.formatargspec(spec[0], spec[1], spec[2])
     defaulted_vals = spec[3] is not None and spec[0][0-len(spec[3]):] or ()
     apply_kw = inspect.formatargspec(spec[0], spec[1], spec[2], defaulted_vals,
index 070ffb5835552a7c3f8f4d189b630f3d23283f05..b23b5632234be5ab84c7cccb65ae1e2308701af7 100644 (file)
@@ -664,7 +664,7 @@ class TestFormatArgspec(TestBase):
            grouped=False)
 
         test(lambda *a: None,
-           {'args': '(*a)', 'self_arg': None,
+           {'args': '(*a)', 'self_arg': 'a[0]',
             'apply_kw': '(*a)', 'apply_pos': '(*a)' })
 
         test(lambda **kw: None,
@@ -672,7 +672,7 @@ class TestFormatArgspec(TestBase):
             'apply_kw': '(**kw)', 'apply_pos': '(**kw)' })
 
         test(lambda *a, **kw: None,
-           {'args': '(*a, **kw)', 'self_arg': None,
+           {'args': '(*a, **kw)', 'self_arg': 'a[0]',
             'apply_kw': '(*a, **kw)', 'apply_pos': '(*a, **kw)' })
 
         test(lambda a, *b: None,