Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken pinfo magic for interface functions #26906

Closed
mwageringel opened this issue Dec 16, 2018 · 20 comments
Closed

Fix broken pinfo magic for interface functions #26906

mwageringel opened this issue Dec 16, 2018 · 20 comments

Comments

@mwageringel
Copy link

For some interfaces, using the IPython %pinfo/%pinfo2 magic or the questionmark syntax for viewing the help and source code fails with an AttributeError (see below).

The interfaces R and Macaulay2 are affected by this, possibly others as well.

This bug occurs in the console as well as the Jupyter notebook. The oldstyle notebook does not seem to be affected. Possibly related: #11913 and #10860.

I found the bug to be caused by sage.misc.sageinspect.sage_getargspec returning None in this case, which apparently is not supported by IPython.

Here is the stack trace:

sage: r.lm?
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-1-955de2536d9d> in <module>()
----> 1 get_ipython().magic(u'pinfo r.lm')

/Applications/SageMath/local/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in magic(self, arg_s)
   2158         magic_name, _, magic_arg_s = arg_s.partition(' ')
   2159         magic_name = magic_name.lstrip(prefilter.ESC_MAGIC)
-> 2160         return self.run_line_magic(magic_name, magic_arg_s)
   2161
   2162     #-------------------------------------------------------------------------

/Applications/SageMath/local/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in run_line_magic(self, magic_name, line)
   2079                 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals
   2080             with self.builtin_trap:
-> 2081                 result = fn(*args,**kwargs)
   2082             return result
   2083

<decorator-gen-74> in pinfo(self, parameter_s, namespaces)

/Applications/SageMath/local/lib/python2.7/site-packages/IPython/core/magic.pyc in <lambda>(f, *a, **k)
    186     # but it's overkill for just that one bit of state.
    187     def magic_deco(arg):
--> 188         call = lambda f, *a, **k: f(*a, **k)
    189
    190         if callable(arg):

/Applications/SageMath/local/lib/python2.7/site-packages/IPython/core/magics/namespace.pyc in pinfo(self, parameter_s, namespaces)
     59         else:
     60             self.shell._inspect('pinfo', oname, detail_level=detail_level,
---> 61                                 namespaces=namespaces)
     62
     63     @line_magic

/Applications/SageMath/local/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in _inspect(self, meth, oname, namespaces, **kw)
   1534             elif meth == 'pinfo':
   1535                 pmethod(info.obj, oname, formatter, info,
-> 1536                         enable_html_pager=self.enable_html_pager, **kw)
   1537             else:
   1538                 pmethod(info.obj, oname)

/Applications/SageMath/local/lib/python2.7/site-packages/IPython/core/oinspect.pyc in pinfo(self, obj, oname, formatter, info, detail_level, enable_html_pager)
    713         - detail_level: if set to 1, more information is given.
    714         """
--> 715         info = self._get_info(obj, oname, formatter, info, detail_level)
    716         if not enable_html_pager:
    717             del info['text/html']

/Applications/SageMath/local/lib/python2.7/site-packages/IPython/core/oinspect.pyc in _get_info(self, obj, oname, formatter, info, detail_level)
    614         """Retrieve an info dict and format it."""
    615
--> 616         info = self._info(obj, oname=oname, info=info, detail_level=detail_level)
    617
    618         _mime = {

/Applications/SageMath/local/lib/python2.7/site-packages/IPython/core/oinspect.pyc in _info(self, obj, oname, info, detail_level)
    944                 # named tuples' _asdict() method returns an OrderedDict, but we
    945                 # we want a normal
--> 946                 out['argspec'] = argspec_dict = dict(argspec._asdict())
    947                 # We called this varkw before argspec became a named tuple.
    948                 # With getfullargspec it's also called varkw.

AttributeError: 'NoneType' object has no attribute '_asdict'

Tested using Sage 8.5.rc1 on OS X and Linux.

Depends on #27200

Upstream: Fixed upstream, in a later stable release.

Component: interfaces

Keywords: pinfo, introspection, IPython, R, macaulay2

Author: Markus Wageringel

Branch/Commit: b1c5aa7

Reviewer: Travis Scrimshaw, Dima Pasechnik

Issue created by migration from https://trac.sagemath.org/ticket/26906

@mwageringel mwageringel added this to the sage-8.6 milestone Dec 16, 2018
@mwageringel
Copy link
Author

Branch: u/gh-mwageringel/interfaces_pinfo

@mwageringel
Copy link
Author

Commit: b1c5aa7

@mwageringel
Copy link
Author

Author: Markus Wageringel

@mwageringel
Copy link
Author

comment:1

I tested the change in the console as well as both the Jupyter and oldstyle notebook in order to test against the issue addressed in #11913 and #10860. I also added IPython doctests for this.


New commits:

b1c5aa7fix broken pinfo magic for interfaces like R

@mwageringel mwageringel changed the title Fix error in pinfo magic for interface functions Fix broken pinfo magic for interface functions Dec 16, 2018
@tscrim
Copy link
Collaborator

tscrim commented Dec 17, 2018

Reviewer: Travis Scrimshaw

@tscrim
Copy link
Collaborator

tscrim commented Dec 17, 2018

comment:3

LGTM.

@tscrim
Copy link
Collaborator

tscrim commented Dec 17, 2018

comment:4

Actually, wait, there is an issue noted by the patchbot:

sage -t --long local/lib/python2.7/site-packages/sagenb/misc/support.py
**********************************************************************
File "local/lib/python2.7/site-packages/sagenb/misc/support.py", line 252, in sagenb.misc.support.docstring
Failed example:
    D = docstring("r.lm", globs=globals())
Expected nothing
Got:
    <string>:5: (WARNING/2) Inline emphasis start-string without end-string.
    <string>:5: (WARNING/2) Inline strong start-string without end-string.
**********************************************************************

@mwageringel
Copy link
Author

comment:5

It turns out this happens when sagenb parses parts of the docstring which changed to

 **Type:** <class 'sage.interfaces.r.RFunction'>

-**Definition:** r.lm( [noargspec] )
+**Definition:** r.lm(*args, **kwds)

 **Docstring:**

Here, the * and ** are incorrectly interpreted as markup. There is an escape mechanism in place for this which requires setting the flag sage.misc.sageinspect.EMBEDDED_MODE. In sagenb, this is usually handled by sagenb.misc.support.init. However, initialization is never done in that specific doctest, so it is just a matter of changing that doctest. I guess I will report this at sagenb.

@mwageringel
Copy link
Author

comment:6

Reported here: sagemath/sagenb#464

@mwageringel
Copy link
Author

Upstream: Reported upstream. No feedback yet.

@embray
Copy link
Contributor

embray commented Jan 15, 2019

comment:7

Retarging tickets optimistically to the next milestone. If you are responsible for this ticket (either its reporter or owner) and don't believe you are likely to complete this ticket before the next release (8.7) please retarget this ticket's milestone to sage-pending or sage-wishlist.

@embray embray modified the milestones: sage-8.6, sage-8.7 Jan 15, 2019
@dimpase
Copy link
Member

dimpase commented Feb 1, 2019

Changed upstream from Reported upstream. No feedback yet. to Fixed upstream, in a later stable release.

@dimpase
Copy link
Member

dimpase commented Feb 1, 2019

comment:8

Replying to @mwageringel:

Reported here: sagemath/sagenb#464

merged upstream.
A new release of sagenb should fix this then.

@dimpase
Copy link
Member

dimpase commented Feb 1, 2019

Dependencies: #27200

@dimpase
Copy link
Member

dimpase commented Feb 1, 2019

comment:9

#27200 - new sagenb release, with the needed patch.

@dimpase
Copy link
Member

dimpase commented Feb 2, 2019

comment:10

I have checked that this patch cures the display of sage: r.lm?.
Could you please check (after installing new sagenb, naturally)
that it also does the thing for %pinfo - something I don't know about - and if it does, set this to positive review...

@dimpase
Copy link
Member

dimpase commented Feb 2, 2019

Changed reviewer from Travis Scrimshaw to Travis Scrimshaw, Dima Pasechnik

@tscrim
Copy link
Collaborator

tscrim commented Feb 7, 2019

comment:11

Patchbot is still getting the same failures as comment:4.

@tscrim
Copy link
Collaborator

tscrim commented Feb 7, 2019

comment:12

Scratch that, it didn't run with the upgraded sagenb. Upgrading sagenb and running that test passes (on linux). So back to positive.

@vbraun
Copy link
Member

vbraun commented Feb 8, 2019

Changed branch from u/gh-mwageringel/interfaces_pinfo to b1c5aa7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants