Skip to content
This repository was archived by the owner on Jan 30, 2023. It is now read-only.

Commit 2e75d4c

Browse files
committed
Add IPython support for Cython functions
1 parent 6fc1e20 commit 2e75d4c

File tree

4 files changed

+57
-1
lines changed

4 files changed

+57
-1
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
5.5.0
1+
5.5.0.p0
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
See https://github.com/ipython/ipython/pull/11139
2+
3+
commit 98e7ddd43bab127de68a3c66870b8e17a5b50eeb
4+
Author: Jeroen Demeyer <[email protected]>
5+
Date: Wed May 16 14:32:15 2018 +0200
6+
7+
Use inspect instead of type checks
8+
9+
diff --git a/IPython/utils/_signatures.py b/IPython/utils/_signatures.py
10+
index 3b53e89..20f52b9 100644
11+
--- a/IPython/utils/_signatures.py
12+
+++ b/IPython/utils/_signatures.py
13+
@@ -21,6 +21,7 @@
14+
import functools
15+
import re
16+
import types
17+
+import inspect
18+
19+
20+
# patch for single-file
21+
@@ -71,7 +72,7 @@ def signature(obj):
22+
if not callable(obj):
23+
raise TypeError('{0!r} is not a callable object'.format(obj))
24+
25+
- if isinstance(obj, types.MethodType):
26+
+ if inspect.ismethod(obj):
27+
if obj.__self__ is None:
28+
# Unbound method - treat it as a function (no distinction in Py 3)
29+
obj = obj.__func__
30+
@@ -96,7 +97,7 @@ def signature(obj):
31+
else:
32+
return signature(wrapped)
33+
34+
- if isinstance(obj, types.FunctionType):
35+
+ if inspect.isfunction(obj):
36+
return Signature.from_function(obj)
37+
38+
if isinstance(obj, functools.partial):
39+
@@ -511,7 +512,7 @@ def __init__(self, parameters=None, return_annotation=_empty,
40+
def from_function(cls, func):
41+
'''Constructs Signature for the given python function'''
42+
43+
- if not isinstance(func, types.FunctionType):
44+
+ if not inspect.isfunction(func):
45+
raise TypeError('{0!r} is not a Python function'.format(func))
46+
47+
Parameter = cls._parameter_cls

src/sage/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ def isfunction(obj):
3939
False
4040
sage: isfunction(Integer(1).digits) # bound method
4141
False
42+
43+
Verify that ipywidgets can correctly determine signatures of Cython
44+
functions::
45+
46+
sage: from ipywidgets.widgets.interaction import signature
47+
sage: from sage.dynamics.complex_dynamics.mandel_julia_helper import fast_mandelbrot_plot
48+
sage: signature(fast_mandelbrot_plot) # random
49+
<IPython.utils._signatures.Signature object at 0x7f3ec8274e10>
4250
"""
4351
# We use type(obj) instead of just obj to avoid __getattr__().
4452
# Some types, like methods, will return the __code__ of the

src/sage/dynamics/complex_dynamics/mandel_julia_helper.pyx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# cython: binding=True
12
r"""
23
Mandelbrot and Julia sets (Cython helper)
34

0 commit comments

Comments
 (0)