<html>
<head>

<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<br>
<br>
One wrinkle of PEP 362 in CPython is callables implemented directly
in C.&nbsp; Right now there's no good way to generate such signatures
automatically.&nbsp; That's why we kept __signature__ in the spec, to
allow implementors to generate signatures by hand for these
callables.<br>
<br>
But the wrinkle gets wrinklier.&nbsp; The problem is, you often can't add
arbitrary attributes to these objects:<br>
<blockquote>&gt;&gt;&gt; import os<br>
&gt;&gt;&gt; os.stat.random_new_attribute = 3<br>
Traceback (most recent call last):<br>
&nbsp; File "&lt;stdin&gt;", line 1, in &lt;module&gt;<br>
AttributeError: 'builtin_function_or_method' object has no
attribute 'random_new_attribute'<br>
</blockquote>
If users are to attach precomputed signatures to callables
implemented in C, those callables may need to *already* have a
__signature__ attribute.<br>
<br>
<br>
I've already added __signature__ to PyCFunctionObject in the PEP 362
patch.&nbsp; This takes care of the vast bulk of such callables.&nbsp; But
there are a bunch of obscure callable objects in CPython, and I
suspect some of them may need a __signature__ attribute.<br>
<br>
Here's an almost- complete list, listed as their Python type:<br>
<blockquote>functools.KeyWrapper (result of functools.cmp_to_key)<br>
weakref.weakref<br>
method (bound method objects, aka "x = Class(); x.method")<br>
instancemethod (is this still even used?&nbsp; it's never used in
trunk)<br>
operator.itemgetter<br>
operator.attrgetter<br>
operator.methodcaller<br>
_json.Scanner (result of _json.make_scanner)<br>
_json.Encoder (result of _json.make_encoder)<br>
_ctypes.DictRemover (I'm not even sure how you can get your hands
on one of these)<br>
sqlite3.Connection<br>
</blockquote>
I produced this by grepping for "/* tp_call */" and ignoring all of
them that were set to "0", then creating one of those objects and
trying (and failing) to set a __signature__ attribute.<br>
<br>
There are four more candidates I found with the grep but couldn't
figure out how to instantiate and test.&nbsp; They have to do with the
descriptor protocol, aka properties, but the types aren't directly
exposed by Python.&nbsp; They're all defined in Object/descrobject.c.&nbsp;
The internal class names are:<br>
<blockquote>
method_descriptor<br>
classmethod_descriptor<br>
wrapper_descriptor<br>
method-wrapper (you get one of these out of a
"wrapper_descriptor")<br>
</blockquote>
<br>
I'm happy to do the work, but I don't have a good sense of which
callables need a __signature__ attribute.&nbsp; Can someone here tell me
which ones might need a __signature__ attribute?<br>
<br>
<br>
<i>/arry</i><br>
</body>
</html>

AltStyle によって変換されたページ (->オリジナル) /