On 02/05/2014 05:52 AM, "Martin v. Löwis" wrote:
D: Add a new type slot for method signatures. This would be a
tp_signature field, along with a new slot id Py_tp_signature. The
signature field itself could be

struct PyMethodSignature {
    char *method_name;
    char *method_signature;
};

That should work too, though we'd also have to add a md_signature field to module objects.

It would probably be best to merge the signature into the callable object anyway. Otherwise we'd have to go look up the signature using __name__ and __self__ / __objclass__ on demand. Maybe that isn't such a big deal, but it gets a little worse: as far as I can tell, there's no attribute on a type object one can use to find the module it lives in. So in this situation:

    >>> import _pickle
    >>> import inspect
    >>> inspect.signature(_pickle.Pickler)

How could inspect.signature figure out that the "Pickler" type object lives in the "_pickle" module? My best guess: parsing the __qualname__, which is pretty ugly.

Also, keeping the signature as a reasonably-human-readable preface to the docstring means that, if we supported this for third-party modules, they could be binary ABI compatible with 3.3 and still have something approximating the hand-written signature at the top of their docstring.

Cheers,


//arry/
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to