Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gwenaël Samain
cython
Commits
de96f31c
Commit
de96f31c
authored
Feb 14, 2014
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support __signature__ property on CyFunction in Py3.4
parent
ee6c58e1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
0 deletions
+46
-0
Cython/Utility/CythonFunction.c
Cython/Utility/CythonFunction.c
+30
-0
tests/run/cyfunction.pyx
tests/run/cyfunction.pyx
+16
-0
No files found.
Cython/Utility/CythonFunction.c
View file @
de96f31c
...
...
@@ -70,6 +70,8 @@ static int __Pyx_CyFunction_init(void);
//////////////////// CythonFunction ////////////////////
//@substitute: naming
//@requires: CommonTypes.c::FetchCommonType
//@requires: ObjectHandling.c::PyObjectCallMethod
//@requires: ObjectHandling.c::PyObjectGetAttrStr
static
PyObject
*
__Pyx_CyFunction_get_doc
(
__pyx_CyFunctionObject
*
op
,
CYTHON_UNUSED
void
*
closure
)
...
...
@@ -347,6 +349,31 @@ __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
=
__Pyx_PyObject_CallMethod1
(
signature_class
,
PYIDENT
(
"from_function"
),
op
);
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
},
{(
char
*
)
"__doc__"
,
(
getter
)
__Pyx_CyFunction_get_doc
,
(
setter
)
__Pyx_CyFunction_set_doc
,
0
,
0
},
...
...
@@ -366,6 +393,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
{
0
,
0
,
0
,
0
,
0
}
};
...
...
tests/run/cyfunction.pyx
View file @
de96f31c
...
...
@@ -55,6 +55,22 @@ 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_dict
():
"""
>>> test_dict.foo = 123
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment