Commit d3589269 authored by Stefan Behnel's avatar Stefan Behnel

get rid of __signature__ property for cyfunctions again as inspect.py in Py3.4...

get rid of __signature__ property for cyfunctions again as inspect.py in Py3.4 can do the same thing more efficiently all by itself now (only commenting it out because it could potentially become a feature again at some point)
parent 52b51422
......@@ -11,9 +11,6 @@ Features added
* Some optimisations for set/frozenset instantiation.
* Cython implemented Python functions export a ``__signature__`` attribute
in Python 3.4.
* Support for C++ unordered_set and unordered_map.
Bugs fixed
......
......@@ -348,30 +348,30 @@ __Pyx_CyFunction_get_annotations(__pyx_CyFunctionObject *op) {
return result;
}
#if PY_VERSION_HEX >= 0x030400C1
static PyObject *
__Pyx_CyFunction_get_signature(__pyx_CyFunctionObject *op) {
PyObject *inspect_module, *signature_class, *signature;
// from inspect import Signature
inspect_module = PyImport_ImportModuleLevelObject(PYIDENT("inspect"), NULL, NULL, NULL, 0);
if (unlikely(!inspect_module))
goto bad;
signature_class = __Pyx_PyObject_GetAttrStr(inspect_module, PYIDENT("Signature"));
Py_DECREF(inspect_module);
if (unlikely(!signature_class))
goto bad;
// return Signature.from_function(op)
signature = PyObject_CallMethodObjArgs(signature_class, PYIDENT("from_function"), op, NULL);
Py_DECREF(signature_class);
if (likely(signature))
return signature;
bad:
// make sure we raise an AttributeError from this property on any errors
if (!PyErr_ExceptionMatches(PyExc_AttributeError))
PyErr_SetString(PyExc_AttributeError, "failed to calculate __signature__");
return NULL;
}
#endif
//#if PY_VERSION_HEX >= 0x030400C1
//static PyObject *
//__Pyx_CyFunction_get_signature(__pyx_CyFunctionObject *op) {
// PyObject *inspect_module, *signature_class, *signature;
// // from inspect import Signature
// inspect_module = PyImport_ImportModuleLevelObject(PYIDENT("inspect"), NULL, NULL, NULL, 0);
// if (unlikely(!inspect_module))
// goto bad;
// signature_class = __Pyx_PyObject_GetAttrStr(inspect_module, PYIDENT("Signature"));
// Py_DECREF(inspect_module);
// if (unlikely(!signature_class))
// goto bad;
// // return Signature.from_function(op)
// signature = PyObject_CallMethodObjArgs(signature_class, PYIDENT("from_function"), op, NULL);
// Py_DECREF(signature_class);
// if (likely(signature))
// return signature;
//bad:
// // make sure we raise an AttributeError from this property on any errors
// if (!PyErr_ExceptionMatches(PyExc_AttributeError))
// PyErr_SetString(PyExc_AttributeError, "failed to calculate __signature__");
// return NULL;
//}
//#endif
static PyGetSetDef __pyx_CyFunction_getsets[] = {
{(char *) "func_doc", (getter)__Pyx_CyFunction_get_doc, (setter)__Pyx_CyFunction_set_doc, 0, 0},
......@@ -392,9 +392,9 @@ static PyGetSetDef __pyx_CyFunction_getsets[] = {
{(char *) "__defaults__", (getter)__Pyx_CyFunction_get_defaults, (setter)__Pyx_CyFunction_set_defaults, 0, 0},
{(char *) "__kwdefaults__", (getter)__Pyx_CyFunction_get_kwdefaults, (setter)__Pyx_CyFunction_set_kwdefaults, 0, 0},
{(char *) "__annotations__", (getter)__Pyx_CyFunction_get_annotations, (setter)__Pyx_CyFunction_set_annotations, 0, 0},
#if PY_VERSION_HEX >= 0x030400C1
{(char *) "__signature__", (getter)__Pyx_CyFunction_get_signature, 0, 0, 0},
#endif
//#if PY_VERSION_HEX >= 0x030400C1
// {(char *) "__signature__", (getter)__Pyx_CyFunction_get_signature, 0, 0, 0},
//#endif
{0, 0, 0, 0, 0}
};
......
......@@ -55,20 +55,20 @@ def inspect_signature(a, b, c=123, *, d=234):
return inspect.signature(inspect_signature) if IS_PY34 else None
def test___signature__(a, b, c=123, *, d=234):
"""
>>> sig = test___signature__(1, 2)
>>> if IS_PY34: list(sig.parameters)
... else: ['a', 'b', 'c', 'd']
['a', 'b', 'c', 'd']
>>> if IS_PY34: sig.parameters['c'].default == 123
... else: True
True
>>> if IS_PY34: sig.parameters['d'].default == 234
... else: True
True
"""
return inspect_signature.__signature__ if IS_PY34 else None
# def test___signature__(a, b, c=123, *, d=234):
# """
# >>> sig = test___signature__(1, 2)
# >>> if IS_PY34: list(sig.parameters)
# ... else: ['a', 'b', 'c', 'd']
# ['a', 'b', 'c', 'd']
# >>> if IS_PY34: sig.parameters['c'].default == 123
# ... else: True
# True
# >>> if IS_PY34: sig.parameters['d'].default == 234
# ... else: True
# True
# """
# return inspect_signature.__signature__ if IS_PY34 else None
def test_dict():
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment