Issue620190
This issue tracker has been migrated to GitHub,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2002-10-08 12:26 by aschmolck, last changed 2022-04-10 16:05 by admin. This issue is now closed.
Messages (4) | |||
---|---|---|---|
msg12645 - (view) | Author: Alexander Schmolck (aschmolck) | Date: 2002-10-08 12:26 | |
inspect.getargspec(NewKlass.aMethod) fails (which might technically be OK because the docs only mention functions, not methods) but I also vaguely seem to remember that some other operations in the inspect module only worked for oldstyle classes under 2.2.1. |
|||
msg12646 - (view) | Author: Michael Stone (mbrierst) | Date: 2003-02-11 22:46 | |
Logged In: YES user_id=670441 Well I think this (one line) patch will make getargspec work with methods, if anyone wants to apply it. Did you find any other operations that don't work? patch: Index: Lib/inspect.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/inspect.py,v retrieving revision 1.41 diff -c -r1.41 inspect.py *** Lib/inspect.py 19 Jan 2003 13:21:20 -0000 1.41 --- Lib/inspect.py 11 Feb 2003 22:35:41 -0000 *************** *** 16,22 **** getmodule() - determine the module that an object came from getclasstree() - arrange classes so as to represent their hierarchy ! getargspec(), getargvalues() - get info about function arguments formatargspec(), formatargvalues() - format an argument spec getouterframes(), getinnerframes() - get info about frames currentframe() - get the current stack frame --- 16,22 ---- getmodule() - determine the module that an object came from getclasstree() - arrange classes so as to represent their hierarchy ! getargspec(), getargvalues() - get info about function or method's arguments formatargspec(), formatargvalues() - format an argument spec getouterframes(), getinnerframes() - get info about frames currentframe() - get the current stack frame *************** *** 625,636 **** return args, varargs, varkw def getargspec(func): ! """Get the names and default values of a function's arguments. A tuple of four things is returned: (args, varargs, varkw, defaults). 'args' is a list of the argument names (it may contain nested lists). 'varargs' and 'varkw' are the names of the * and ** arguments or None. 'defaults' is an n-tuple of the default values of the last n arguments.""" if not isfunction(func): raise TypeError, 'arg is not a Python function' args, varargs, varkw = getargs(func.func_code) return args, varargs, varkw, func.func_defaults --- 625,637 ---- return args, varargs, varkw def getargspec(func): ! """Get the names and default values of a function or method's arguments. A tuple of four things is returned: (args, varargs, varkw, defaults). 'args' is a list of the argument names (it may contain nested lists). 'varargs' and 'varkw' are the names of the * and ** arguments or None. 'defaults' is an n-tuple of the default values of the last n arguments.""" + if ismethod(func): func = func.im_func if not isfunction(func): raise TypeError, 'arg is not a Python function' args, varargs, varkw = getargs(func.func_code) return args, varargs, varkw, func.func_defaults |
|||
msg12647 - (view) | Author: Alexander Schmolck (aschmolck) | Date: 2003-06-22 17:05 | |
Logged In: YES user_id=559641 a late reply RE: other problems (the notification I received from SF for a (mysterious) 'settings change' prompted me to look at this report again). There doesn't seem to be a straightforwad way to test for (instance) "methodness". For example, I think it ought to be easy to get the instance, class and/or staticmethods of something, independent of whether it is old-style class, new-style class or builtin type etc., which to most extents and purposes is an insignificant implementation detail. For example, I doubt the following will do what the casual programmer expects: >>> inspect.getmembers(foo, inspect.ismethod) because foo might e.g. be a Numeric.array. The only function in `inspect` that returns something along those lines that is useful and understandable to someone who hasn't got the most exquisite knowledge about python's old-style/new-style/builin-type, method-wrapper, __slots__ etc. chaos is `classify_class_attrs', only that this doesn't work for types or classes with __slots__ (at least the latter ought to be fixed) and also packages together functionality that I think should exist seperately. |
|||
msg12648 - (view) | Author: Jeremy Hylton (jhylton) | Date: 2003-06-28 17:25 | |
Logged In: YES user_id=31392 The simple fix for getargspec() was checked in. I'm not going to do anything about the methodness suggestion. I don't think Python has a clear notion of which attributes are methods and which are not. |
History | |||
---|---|---|---|
Date | User | Action | Args |
2022-04-10 16:05:44 | admin | set | github: 37284 |
2002-10-08 12:26:12 | aschmolck | create |