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

Commit

Permalink
Add IPython support for Cython functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jdemeyer committed May 16, 2018
1 parent 6fc1e20 commit 2e75d4c
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build/pkgs/ipython/package-version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.5.0
5.5.0.p0
47 changes: 47 additions & 0 deletions build/pkgs/ipython/patches/signature.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
See https://github.com/ipython/ipython/pull/11139

commit 98e7ddd43bab127de68a3c66870b8e17a5b50eeb
Author: Jeroen Demeyer <jdemeyer@cage.ugent.be>
Date: Wed May 16 14:32:15 2018 +0200

Use inspect instead of type checks

diff --git a/IPython/utils/_signatures.py b/IPython/utils/_signatures.py
index 3b53e89..20f52b9 100644
--- a/IPython/utils/_signatures.py
+++ b/IPython/utils/_signatures.py
@@ -21,6 +21,7 @@
import functools
import re
import types
+import inspect


# patch for single-file
@@ -71,7 +72,7 @@ def signature(obj):
if not callable(obj):
raise TypeError('{0!r} is not a callable object'.format(obj))

- if isinstance(obj, types.MethodType):
+ if inspect.ismethod(obj):
if obj.__self__ is None:
# Unbound method - treat it as a function (no distinction in Py 3)
obj = obj.__func__
@@ -96,7 +97,7 @@ def signature(obj):
else:
return signature(wrapped)

- if isinstance(obj, types.FunctionType):
+ if inspect.isfunction(obj):
return Signature.from_function(obj)

if isinstance(obj, functools.partial):
@@ -511,7 +512,7 @@ def __init__(self, parameters=None, return_annotation=_empty,
def from_function(cls, func):
'''Constructs Signature for the given python function'''

- if not isinstance(func, types.FunctionType):
+ if not inspect.isfunction(func):
raise TypeError('{0!r} is not a Python function'.format(func))

Parameter = cls._parameter_cls
8 changes: 8 additions & 0 deletions src/sage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ def isfunction(obj):
False
sage: isfunction(Integer(1).digits) # bound method
False
Verify that ipywidgets can correctly determine signatures of Cython
functions::
sage: from ipywidgets.widgets.interaction import signature
sage: from sage.dynamics.complex_dynamics.mandel_julia_helper import fast_mandelbrot_plot
sage: signature(fast_mandelbrot_plot) # random
<IPython.utils._signatures.Signature object at 0x7f3ec8274e10>
"""
# We use type(obj) instead of just obj to avoid __getattr__().
# Some types, like methods, will return the __code__ of the
Expand Down
1 change: 1 addition & 0 deletions src/sage/dynamics/complex_dynamics/mandel_julia_helper.pyx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# cython: binding=True
r"""
Mandelbrot and Julia sets (Cython helper)
Expand Down

0 comments on commit 2e75d4c

Please sign in to comment.