<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix"><br>
<br>
On 02/24/2015 05:56 PM, Gregory P. Smith wrote:<br>
</div>
<blockquote
cite="mid:CAGE7PNLmGz6Aju0KG-6ygDavY9Ksn9p82tAaF4d18=gEcoDjtQ@mail.gmail.com"
type="cite">
<div dir="ltr">inspect.getargspec(method) and
inspect.signature(method) both include the 'self' parameter but
how are we to figure out from method itself that it is actually
bound and that its first parameter is expected to be a bound
instance?</div>
</blockquote>
<br>
Given the mechanisms involved, surely this question is a bit
nonsensical? The function doesn't "expect" anything, it's just a
function. (I remind you, Python 3 dropped the whole concept of an
"unbound method".) If it happens to live inside a class, and it's
accessed through an instance of the class, then the first parameter
gets bound.<br>
<br>
Consider:<br>
<blockquote>>>> class A:<br>
... def x(self, a): print(a)<br>
... <br>
>>> a = A()<br>
</blockquote>
inspect.signature(A.x).parameters has two parameters, "self" and
"a".<br>
inspect.signature(a.x).parameters has only one parameter, "a".<br>
<br>
I claiim this is what you want. It's analagous to a
functools.partial object. It would be awfully confusing if the
signature of a functools.partial object include the parameters
handled by the partial object.<br>
<br>
IMO inspect.getargspec and inspect.getfullargspec get this wrong;
for a.x they include the "self" parameter. If you were constructing
a call to this function dynamically you'd include one too many
parameters.<br>
<br>
<br>
<i>/arry</i><br>
</body>
</html>