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

Latest commit

 

History

History
1152 lines (902 loc) · 46.9 KB

20626.md

File metadata and controls

1152 lines (902 loc) · 46.9 KB

Issue 20626: Introspection of lazy_import'ed modules crashes Sage

archive/issues_020389.json:

{
    "assignees": [],
    "body": "<div id=\"comment:0\"></div>\n\n**Steps to reproduce**: extract the attached archive containing a trivial module bar lazy imported from a module foo in the current directory, and run sage:\n\n```\nsage: import foo\nsage: foo.bar?\n---------------------------------------------------------------------------\nRuntimeError                              Traceback (most recent call last)\n<ipython-input-2-04fe32111b22> in <module>()\n----> 1 get_ipython().magic(u'pinfo foo.bar')\n\n/opt/sage-git/local/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in magic(self, arg_s)\n   2161         magic_name, _, magic_arg_s = arg_s.partition(' ')\n   2162         magic_name = magic_name.lstrip(prefilter.ESC_MAGIC)\n-> 2163         return self.run_line_magic(magic_name, magic_arg_s)\n   2164 \n   2165     #-------------------------------------------------------------------------\n\n\n... last 3 frames repeated, from the frame below ...\n\n/opt/sage-git/local/lib/python2.7/site-packages/sage/misc/sageinspect.pyc in sage_getdoc_original(obj)\n   1765         typ = type(obj)\n   1766 \n-> 1767     s,argspec = _extract_embedded_signature(_sage_getdoc_unformatted(obj), typ.__name__)\n   1768     if s:\n   1769         pos = _extract_embedded_position(s)\n\nRuntimeError: maximum recursion depth exceeded in __instancecheck__\n```\n\n**Analysis**: sage.misc.sageinspect.sage_getdoc_original gets confused\nwhen detecting that `foo.bar` is of type `LazyImport` (and not module)\nand trying to recover its documentation from there.\n\n\n**Use case**: some Sage modules contain only documentation:\n\n- `sage.combinat.tutorial`\n- `sage.combinat.primer`\n- `sage.modules.tutorial_free_module`\n- `sage.categories.primer`\n- `sage.categories.tutorial`\n\nand more will come. It would be nice to lazy import them to reduce the\nmemory and startup footprint.\n\nThis requires a simple IPython patch: https://github.com/ipython/ipython/pull/10426\n\nUpstream: **Fixed upstream, in a later stable release.**\n\nCC:  @jdemeyer @videlec @kliem\n\nComponent: **misc**\n\n_Issue created by migration from https://trac.sagemath.org/ticket/20626_\n\n",
    "created_at": "2016-05-19T07:08:23Z",
    "labels": [
        "https://github.com/sagemath/sage/labels/p%3A%20major%20/%203",
        "https://github.com/sagemath/sage/labels/bug"
    ],
    "reactions": [],
    "repository": "https://github.com/sagemath/sage",
    "title": "Introspection of lazy_import'ed modules crashes Sage",
    "type": "issue",
    "updated_at": "2022-12-29T01:42:26Z",
    "url": "https://github.com/sagemath/sage/issues/20626",
    "user": "https://github.com/nthiery"
}

Steps to reproduce: extract the attached archive containing a trivial module bar lazy imported from a module foo in the current directory, and run sage:

sage: import foo
sage: foo.bar?
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-2-04fe32111b22> in <module>()
----> 1 get_ipython().magic(u'pinfo foo.bar')

/opt/sage-git/local/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in magic(self, arg_s)
   2161         magic_name, _, magic_arg_s = arg_s.partition(' ')
   2162         magic_name = magic_name.lstrip(prefilter.ESC_MAGIC)
-> 2163         return self.run_line_magic(magic_name, magic_arg_s)
   2164 
   2165     #-------------------------------------------------------------------------


... last 3 frames repeated, from the frame below ...

/opt/sage-git/local/lib/python2.7/site-packages/sage/misc/sageinspect.pyc in sage_getdoc_original(obj)
   1765         typ = type(obj)
   1766 
-> 1767     s,argspec = _extract_embedded_signature(_sage_getdoc_unformatted(obj), typ.__name__)
   1768     if s:
   1769         pos = _extract_embedded_position(s)

RuntimeError: maximum recursion depth exceeded in __instancecheck__

Analysis: sage.misc.sageinspect.sage_getdoc_original gets confused when detecting that foo.bar is of type LazyImport (and not module) and trying to recover its documentation from there.

Use case: some Sage modules contain only documentation:

  • sage.combinat.tutorial
  • sage.combinat.primer
  • sage.modules.tutorial_free_module
  • sage.categories.primer
  • sage.categories.tutorial

and more will come. It would be nice to lazy import them to reduce the memory and startup footprint.

This requires a simple IPython patch: ipython/ipython#10426

Upstream: Fixed upstream, in a later stable release.

CC: @jdemeyer @videlec @kliem

Component: misc

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


archive/issue_events_287933.json:

{
    "actor": "https://github.com/nthiery",
    "created_at": "2016-05-19T07:08:23Z",
    "event": "milestoned",
    "issue": "https://github.com/sagemath/sage/issues/20626",
    "milestone_number": null,
    "milestone_title": "sage-7.3",
    "type": "issue_event",
    "url": "https://github.com/sagemath/sage/issues/20626#event-287933"
}

archive/issue_events_287934.json:

{
    "actor": "https://github.com/nthiery",
    "created_at": "2016-05-19T07:08:23Z",
    "event": "labeled",
    "issue": "https://github.com/sagemath/sage/issues/20626",
    "label": "https://github.com/sagemath/sage/labels/p%3A%20major%20/%203",
    "label_color": "ffbb00",
    "label_name": "p: major / 3",
    "label_text_color": "ffffff",
    "type": "issue_event",
    "url": "https://github.com/sagemath/sage/issues/20626#event-287934"
}

archive/issue_events_287935.json:

{
    "actor": "https://github.com/nthiery",
    "created_at": "2016-05-19T07:08:23Z",
    "event": "labeled",
    "issue": "https://github.com/sagemath/sage/issues/20626",
    "label": "https://github.com/sagemath/sage/labels/bug",
    "label_color": "d73a4a",
    "label_name": "bug",
    "label_text_color": "ffffff",
    "type": "issue_event",
    "url": "https://github.com/sagemath/sage/issues/20626#event-287935"
}

archive/issue_comments_298210.json:

{
    "body": "<div id=\"comment:2\" align=\"right\">comment:2</div>\n\nPossibly related: documentation of lazy imports includes various `lazy_import` stuff\n\n```\nsage: %pinfo piecewise\nType:            LazyImport\nString form:     piecewise\nFile:            ~/Sage/src/sage/misc/lazy_import.pyx\nDocstring:\n   Piecewise function    <---- this section is the only one that is correct\n\n   EXAMPLES:\n\n      sage: var('x, y')\n      (x, y)\n      sage: f = piecewise([((0,1), x^2*y), ([-1,0], -x*y^2)], var=x);  f\n      piecewise(x|-->x^2*y on (0, 1), x|-->-x*y^2 on [-1, 0]; x)\n      sage: f(1/2)\n      1/4*y\n      sage: f(-1/2)\n      1/2*y^2\n\nClass docstring:\n   EXAMPLES:\n\n      sage: from sage.misc.lazy_import import LazyImport\n      sage: my_integer = LazyImport('sage.rings.all', 'Integer')\n      sage: my_integer(4)\n      4\n      sage: my_integer('101', base=2)\n      5\n      sage: my_integer(3/2)\n      Traceback (most recent call last):\n      ...\n      TypeError: no conversion of this rational to integer\nInit docstring:\n   EXAMPLES:\n\n      sage: from sage.misc.lazy_import import LazyImport\n      sage: my_isprime = LazyImport('sage.all', 'is_prime')\n      sage: my_isprime(5)\n      True\n      sage: my_isprime(55)\n      False\nCall docstring:\n   Calling self calls the wrapped object.\n\n   EXAMPLES:\n\n      sage: from sage.misc.lazy_import import LazyImport\n      sage: my_isprime = LazyImport('sage.all', 'is_prime')\n      sage: my_isprime(12)\n      False\n      sage: my_isprime(13)\n      True\n```",
    "created_at": "2016-05-22T08:47:37Z",
    "formatter": "markdown",
    "issue": "https://github.com/sagemath/sage/issues/20626",
    "type": "issue_comment",
    "url": "https://github.com/sagemath/sage/issues/20626#issuecomment-298210",
    "user": "https://github.com/vbraun"
}
comment:2

Possibly related: documentation of lazy imports includes various lazy_import stuff

sage: %pinfo piecewise
Type:            LazyImport
String form:     piecewise
File:            ~/Sage/src/sage/misc/lazy_import.pyx
Docstring:
   Piecewise function    <---- this section is the only one that is correct

   EXAMPLES:

      sage: var('x, y')
      (x, y)
      sage: f = piecewise([((0,1), x^2*y), ([-1,0], -x*y^2)], var=x);  f
      piecewise(x|-->x^2*y on (0, 1), x|-->-x*y^2 on [-1, 0]; x)
      sage: f(1/2)
      1/4*y
      sage: f(-1/2)
      1/2*y^2

Class docstring:
   EXAMPLES:

      sage: from sage.misc.lazy_import import LazyImport
      sage: my_integer = LazyImport('sage.rings.all', 'Integer')
      sage: my_integer(4)
      4
      sage: my_integer('101', base=2)
      5
      sage: my_integer(3/2)
      Traceback (most recent call last):
      ...
      TypeError: no conversion of this rational to integer
Init docstring:
   EXAMPLES:

      sage: from sage.misc.lazy_import import LazyImport
      sage: my_isprime = LazyImport('sage.all', 'is_prime')
      sage: my_isprime(5)
      True
      sage: my_isprime(55)
      False
Call docstring:
   Calling self calls the wrapped object.

   EXAMPLES:

      sage: from sage.misc.lazy_import import LazyImport
      sage: my_isprime = LazyImport('sage.all', 'is_prime')
      sage: my_isprime(12)
      False
      sage: my_isprime(13)
      True

archive/issue_events_287936.json:

{
    "actor": "https://github.com/jdemeyer",
    "created_at": "2017-04-06T12:04:00Z",
    "event": "renamed",
    "issue": "https://github.com/sagemath/sage/issues/20626",
    "title_is": "Introspection of lazy_import'ed modules crashes Sage",
    "title_was": "lazy_import'ed modules broken on introspection",
    "type": "issue_event",
    "url": "https://github.com/sagemath/sage/issues/20626#event-287936"
}

archive/issue_events_287937.json:

{
    "actor": "https://github.com/jdemeyer",
    "created_at": "2017-04-06T12:04:00Z",
    "event": "demilestoned",
    "issue": "https://github.com/sagemath/sage/issues/20626",
    "milestone_number": null,
    "milestone_title": "sage-7.3",
    "type": "issue_event",
    "url": "https://github.com/sagemath/sage/issues/20626#event-287937"
}

archive/issue_events_287938.json:

{
    "actor": "https://github.com/jdemeyer",
    "created_at": "2017-04-06T12:04:00Z",
    "event": "milestoned",
    "issue": "https://github.com/sagemath/sage/issues/20626",
    "milestone_number": null,
    "milestone_title": "sage-8.0",
    "type": "issue_event",
    "url": "https://github.com/sagemath/sage/issues/20626#event-287938"
}

archive/issue_comments_298211.json:

{
    "body": "Description changed:\n``````diff\n--- \n+++ \n@@ -1,33 +1,29 @@\n-*Steps to reproduce*: extract the attached archive containing a\n-trivial module bar lazy imported from a module foo in the current\n-directory, and run sage:\n+*Steps to reproduce*: apply this patch:\n+\n+```diff\n+diff --git a/src/sage/combinat/__init__.py b/src/sage/combinat/__init__.py\n+index 24242dd..220794c 100644\n+--- a/src/sage/combinat/__init__.py\n++++ b/src/sage/combinat/__init__.py\n+@@ -43,5 +43,9 @@ Related topics\n+ - :ref:`sage.graphs`\n+ \n+ \"\"\"\n+-from . import quickref\n+-from . import tutorial\n++\n++from sage.misc.lazy_import import lazyimport\n++\n++with lazyimport:\n++    from . import quickref\n++    from . import tutorial\n+```\n+\n+And run Sage:\n \n ```\n-sage: import foo\n-sage: foo.bar?\n----------------------------------------------------------------------------\n-RuntimeError                              Traceback (most recent call last)\n-<ipython-input-2-04fe32111b22> in <module>()\n-----> 1 get_ipython().magic(u'pinfo foo.bar')\n-\n-/opt/sage-git/local/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in magic(self, arg_s)\n-   2161         magic_name, _, magic_arg_s = arg_s.partition(' ')\n-   2162         magic_name = magic_name.lstrip(prefilter.ESC_MAGIC)\n--> 2163         return self.run_line_magic(magic_name, magic_arg_s)\n-   2164 \n-   2165     #-------------------------------------------------------------------------\n-\n-\n-... last 3 frames repeated, from the frame below ...\n-\n-/opt/sage-git/local/lib/python2.7/site-packages/sage/misc/sageinspect.pyc in sage_getdoc_original(obj)\n-   1765         typ = type(obj)\n-   1766 \n--> 1767     s,argspec = _extract_embedded_signature(_sage_getdoc_unformatted(obj), typ.__name__)\n-   1768     if s:\n-   1769         pos = _extract_embedded_position(s)\n-\n-RuntimeError: maximum recursion depth exceeded in __instancecheck__\n+sage: sage.combinat.tutorial?\n+Segmentation fault\n ```\n \n *Analysis*: sage.misc.sageinspect.sage_getdoc_original gets confused\n``````\n",
    "created_at": "2017-04-06T12:04:00Z",
    "formatter": "markdown",
    "issue": "https://github.com/sagemath/sage/issues/20626",
    "type": "issue_comment",
    "url": "https://github.com/sagemath/sage/issues/20626#issuecomment-298211",
    "user": "https://github.com/jdemeyer"
}

Description changed:

--- 
+++ 
@@ -1,33 +1,29 @@
-*Steps to reproduce*: extract the attached archive containing a
-trivial module bar lazy imported from a module foo in the current
-directory, and run sage:
+*Steps to reproduce*: apply this patch:
+
+```diff
+diff --git a/src/sage/combinat/__init__.py b/src/sage/combinat/__init__.py
+index 24242dd..220794c 100644
+--- a/src/sage/combinat/__init__.py
++++ b/src/sage/combinat/__init__.py
+@@ -43,5 +43,9 @@ Related topics
+ - :ref:`sage.graphs`
+ 
+ """
+-from . import quickref
+-from . import tutorial
++
++from sage.misc.lazy_import import lazyimport
++
++with lazyimport:
++    from . import quickref
++    from . import tutorial
+```
+
+And run Sage:
 
 ```
-sage: import foo
-sage: foo.bar?
----------------------------------------------------------------------------
-RuntimeError                              Traceback (most recent call last)
-<ipython-input-2-04fe32111b22> in <module>()
-----> 1 get_ipython().magic(u'pinfo foo.bar')
-
-/opt/sage-git/local/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in magic(self, arg_s)
-   2161         magic_name, _, magic_arg_s = arg_s.partition(' ')
-   2162         magic_name = magic_name.lstrip(prefilter.ESC_MAGIC)
--> 2163         return self.run_line_magic(magic_name, magic_arg_s)
-   2164 
-   2165     #-------------------------------------------------------------------------
-
-
-... last 3 frames repeated, from the frame below ...
-
-/opt/sage-git/local/lib/python2.7/site-packages/sage/misc/sageinspect.pyc in sage_getdoc_original(obj)
-   1765         typ = type(obj)
-   1766 
--> 1767     s,argspec = _extract_embedded_signature(_sage_getdoc_unformatted(obj), typ.__name__)
-   1768     if s:
-   1769         pos = _extract_embedded_position(s)
-
-RuntimeError: maximum recursion depth exceeded in __instancecheck__
+sage: sage.combinat.tutorial?
+Segmentation fault
 ```
 
 *Analysis*: sage.misc.sageinspect.sage_getdoc_original gets confused

archive/issue_comments_298212.json:

{
    "body": "Dependencies: **#15648**",
    "created_at": "2017-04-06T12:04:00Z",
    "formatter": "markdown",
    "issue": "https://github.com/sagemath/sage/issues/20626",
    "type": "issue_comment",
    "url": "https://github.com/sagemath/sage/issues/20626#issuecomment-298212",
    "user": "https://github.com/jdemeyer"
}

Dependencies: #15648


archive/issue_comments_298213.json:

{
    "body": "Description changed:\n``````diff\n--- \n+++ \n@@ -12,9 +12,9 @@\n -from . import quickref\n -from . import tutorial\n +\n-+from sage.misc.lazy_import import lazyimport\n++from sage.misc.lazy_import import _lazyimport_\n +\n-+with lazyimport:\n++with _lazyimport_:\n +    from . import quickref\n +    from . import tutorial\n ```\n``````\n",
    "created_at": "2017-04-06T12:36:03Z",
    "formatter": "markdown",
    "issue": "https://github.com/sagemath/sage/issues/20626",
    "type": "issue_comment",
    "url": "https://github.com/sagemath/sage/issues/20626#issuecomment-298213",
    "user": "https://github.com/jdemeyer"
}

Description changed:

--- 
+++ 
@@ -12,9 +12,9 @@
 -from . import quickref
 -from . import tutorial
 +
-+from sage.misc.lazy_import import lazyimport
++from sage.misc.lazy_import import _lazyimport_
 +
-+with lazyimport:
++with _lazyimport_:
 +    from . import quickref
 +    from . import tutorial
 ```

archive/issue_comments_298214.json:

{
    "body": "Description changed:\n``````diff\n--- \n+++ \n@@ -1,4 +1,4 @@\n-*Steps to reproduce*: apply this patch:\n+**Steps to reproduce**: apply this patch:\n \n ```diff\n diff --git a/src/sage/combinat/__init__.py b/src/sage/combinat/__init__.py\n@@ -26,12 +26,12 @@\n Segmentation fault\n ```\n \n-*Analysis*: sage.misc.sageinspect.sage_getdoc_original gets confused\n+**Analysis**: sage.misc.sageinspect.sage_getdoc_original gets confused\n when detecting that `foo.bar` is of type `LazyImport` (and not module)\n and trying to recover its documentation from there.\n \n \n-*Use case*: some Sage modules contain only documentation:\n+**Use case**: some Sage modules contain only documentation:\n \n - `sage.combinat.tutorial`\n - `sage.combinat.primer`\n``````\n",
    "created_at": "2017-04-06T12:37:05Z",
    "formatter": "markdown",
    "issue": "https://github.com/sagemath/sage/issues/20626",
    "type": "issue_comment",
    "url": "https://github.com/sagemath/sage/issues/20626#issuecomment-298214",
    "user": "https://github.com/jdemeyer"
}

Description changed:

--- 
+++ 
@@ -1,4 +1,4 @@
-*Steps to reproduce*: apply this patch:
+**Steps to reproduce**: apply this patch:
 
 ```diff
 diff --git a/src/sage/combinat/__init__.py b/src/sage/combinat/__init__.py
@@ -26,12 +26,12 @@
 Segmentation fault
 ```
 
-*Analysis*: sage.misc.sageinspect.sage_getdoc_original gets confused
+**Analysis**: sage.misc.sageinspect.sage_getdoc_original gets confused
 when detecting that `foo.bar` is of type `LazyImport` (and not module)
 and trying to recover its documentation from there.
 
 
-*Use case*: some Sage modules contain only documentation:
+**Use case**: some Sage modules contain only documentation:
 
 - `sage.combinat.tutorial`
 - `sage.combinat.primer`

archive/issue_comments_298215.json:

{
    "body": "Author: **Jeroen Demeyer**",
    "created_at": "2017-04-06T13:24:43Z",
    "formatter": "markdown",
    "issue": "https://github.com/sagemath/sage/issues/20626",
    "type": "issue_comment",
    "url": "https://github.com/sagemath/sage/issues/20626#issuecomment-298215",
    "user": "https://github.com/jdemeyer"
}

Author: Jeroen Demeyer


archive/issue_comments_298216.json:

{
    "body": "Description changed:\n``````diff\n--- \n+++ \n@@ -42,3 +42,4 @@\n and more will come. It would be nice to lazy import them to reduce the\n memory and startup footprint.\n \n+This requires a simple IPython patch: https://github.com/ipython/ipython/pull/10426\n``````\n",
    "created_at": "2017-04-06T13:24:43Z",
    "formatter": "markdown",
    "issue": "https://github.com/sagemath/sage/issues/20626",
    "type": "issue_comment",
    "url": "https://github.com/sagemath/sage/issues/20626#issuecomment-298216",
    "user": "https://github.com/jdemeyer"
}

Description changed:

--- 
+++ 
@@ -42,3 +42,4 @@
 and more will come. It would be nice to lazy import them to reduce the
 memory and startup footprint.
 
+This requires a simple IPython patch: https://github.com/ipython/ipython/pull/10426

archive/issue_comments_298217.json:

{
    "body": "Upstream: **Reported upstream. No feedback yet.**",
    "created_at": "2017-04-06T13:24:43Z",
    "formatter": "markdown",
    "issue": "https://github.com/sagemath/sage/issues/20626",
    "type": "issue_comment",
    "url": "https://github.com/sagemath/sage/issues/20626#issuecomment-298217",
    "user": "https://github.com/jdemeyer"
}

Upstream: Reported upstream. No feedback yet.


archive/issue_comments_298218.json:

{
    "body": "Branch: **[u/jdemeyer/ticket/20626](https://github.com/sagemath/sagetrac-mirror/tree/u/jdemeyer/ticket/20626)**",
    "created_at": "2017-04-06T13:43:04Z",
    "formatter": "markdown",
    "issue": "https://github.com/sagemath/sage/issues/20626",
    "type": "issue_comment",
    "url": "https://github.com/sagemath/sage/issues/20626#issuecomment-298218",
    "user": "https://github.com/jdemeyer"
}

Branch: u/jdemeyer/ticket/20626


archive/issue_comments_298219.json:

{
    "body": "<div id=\"comment:8\"></div>\n\nLast 10 new commits:\n<table><tr><td><a href=\"https://github.com/sagemath/sagetrac-mirror/commit/8aac18a6b165bc397ccaeaba0b596797e900b0f1\"><code>8aac18a</code></a></td><td><code>Various improvements to lazy imports</code></td></tr><tr><td><a href=\"https://github.com/sagemath/sagetrac-mirror/commit/8ec9f5d89dc2f92c1208239089453a8ec2065b72\"><code>8ec9f5d</code></a></td><td><code>Lazy import context based on __import__</code></td></tr><tr><td><a href=\"https://github.com/sagemath/sagetrac-mirror/commit/d50f9a6fd601c890baec160ac2b80f007cf258aa\"><code>d50f9a6</code></a></td><td><code>Make \"with lazyimport\" context more thread-safe</code></td></tr><tr><td><a href=\"https://github.com/sagemath/sagetrac-mirror/commit/3d62c9e7810c3d7550a82bb8b93d03e1f228ea72\"><code>3d62c9e</code></a></td><td><code>Update documentation</code></td></tr><tr><td><a href=\"https://github.com/sagemath/sagetrac-mirror/commit/9e1208b437e7855a6989a0ea42e42553f2772a84\"><code>9e1208b</code></a></td><td><code>lazyimport -> _lazyimport_</code></td></tr><tr><td><a href=\"https://github.com/sagemath/sagetrac-mirror/commit/796a45277a23c14ea86126f5e08349f2c25c34d2\"><code>796a452</code></a></td><td><code>Search for object in __get__</code></td></tr><tr><td><a href=\"https://github.com/sagemath/sagetrac-mirror/commit/a393dd19d22c0a42ce97799ef083cc7d7270934c\"><code>a393dd1</code></a></td><td><code>Delete lazy import from namespace before doing real import</code></td></tr><tr><td><a href=\"https://github.com/sagemath/sagetrac-mirror/commit/565ee68db4ddd7e5d026957c1b99a088634f7a29\"><code>565ee68</code></a></td><td><code>Patch IPython to ignore all exceptions from getargspec()</code></td></tr><tr><td><a href=\"https://github.com/sagemath/sagetrac-mirror/commit/3840f1ed009a80084f94c58bd7f2553b166baf85\"><code>3840f1e</code></a></td><td><code>Lazy import combinat documentation</code></td></tr><tr><td><a href=\"https://github.com/sagemath/sagetrac-mirror/commit/f25a7d7416b54f4b7e9fac0fb9c9c50fb10bb0a5\"><code>f25a7d7</code></a></td><td><code>Return the actual `__doc__`, not sage_getdoc_original()</code></td></tr></table>\n",
    "created_at": "2017-04-06T13:45:01Z",
    "formatter": "markdown",
    "issue": "https://github.com/sagemath/sage/issues/20626",
    "type": "issue_comment",
    "url": "https://github.com/sagemath/sage/issues/20626#issuecomment-298219",
    "user": "https://github.com/jdemeyer"
}

Last 10 new commits:

8aac18aVarious improvements to lazy imports
8ec9f5dLazy import context based on __import__
d50f9a6Make "with lazyimport" context more thread-safe
3d62c9eUpdate documentation
9e1208blazyimport -> _lazyimport_
796a452Search for object in __get__
a393dd1Delete lazy import from namespace before doing real import
565ee68Patch IPython to ignore all exceptions from getargspec()
3840f1eLazy import combinat documentation
f25a7d7Return the actual `__doc__`, not sage_getdoc_original()

archive/issue_events_287939.json:

{
    "actor": "https://github.com/jdemeyer",
    "created_at": "2017-04-06T13:45:01Z",
    "event": "labeled",
    "issue": "https://github.com/sagemath/sage/issues/20626",
    "label": "https://github.com/sagemath/sage/labels/needs%20review",
    "label_color": "7fff00",
    "label_name": "needs review",
    "label_text_color": "ffffff",
    "type": "issue_event",
    "url": "https://github.com/sagemath/sage/issues/20626#event-287939"
}

archive/issue_comments_298220.json:

{
    "body": "Commit: **[`f25a7d7`](https://github.com/sagemath/sagetrac-mirror/commit/f25a7d7416b54f4b7e9fac0fb9c9c50fb10bb0a5)**",
    "created_at": "2017-04-06T13:45:01Z",
    "formatter": "markdown",
    "issue": "https://github.com/sagemath/sage/issues/20626",
    "type": "issue_comment",
    "url": "https://github.com/sagemath/sage/issues/20626#issuecomment-298220",
    "user": "https://github.com/jdemeyer"
}

Commit: f25a7d7


archive/issue_events_287940.json:

{
    "actor": "https://github.com/jdemeyer",
    "created_at": "2017-04-06T20:16:13Z",
    "event": "demilestoned",
    "issue": "https://github.com/sagemath/sage/issues/20626",
    "milestone_number": null,
    "milestone_title": "sage-8.0",
    "type": "issue_event",
    "url": "https://github.com/sagemath/sage/issues/20626#event-287940"
}

archive/issue_events_287941.json:

{
    "actor": "https://github.com/jdemeyer",
    "created_at": "2017-04-06T20:16:13Z",
    "event": "unlabeled",
    "issue": "https://github.com/sagemath/sage/issues/20626",
    "label": "https://github.com/sagemath/sage/labels/p%3A%20major%20/%203",
    "label_color": "ffbb00",
    "label_name": "p: major / 3",
    "label_text_color": "ffffff",
    "type": "issue_event",
    "url": "https://github.com/sagemath/sage/issues/20626#event-287941"
}

archive/issue_events_287942.json:

{
    "actor": "https://github.com/jdemeyer",
    "created_at": "2017-04-06T20:16:13Z",
    "event": "labeled",
    "issue": "https://github.com/sagemath/sage/issues/20626",
    "label": "https://github.com/sagemath/sage/labels/wontfix",
    "label_color": "c6c6c6",
    "label_name": "wontfix",
    "label_text_color": "ffffff",
    "type": "issue_event",
    "url": "https://github.com/sagemath/sage/issues/20626#event-287942"
}

archive/issue_events_287943.json:

{
    "actor": "https://github.com/jdemeyer",
    "created_at": "2017-04-06T20:16:13Z",
    "event": "unlabeled",
    "issue": "https://github.com/sagemath/sage/issues/20626",
    "label": "https://github.com/sagemath/sage/labels/needs%20review",
    "label_color": "7fff00",
    "label_name": "needs review",
    "label_text_color": "ffffff",
    "type": "issue_event",
    "url": "https://github.com/sagemath/sage/issues/20626#event-287943"
}

archive/issue_events_287944.json:

{
    "actor": "https://github.com/jdemeyer",
    "created_at": "2017-04-06T20:16:13Z",
    "event": "closed",
    "issue": "https://github.com/sagemath/sage/issues/20626",
    "type": "issue_event",
    "url": "https://github.com/sagemath/sage/issues/20626#event-287944"
}

archive/issue_events_287945.json:

{
    "actor": "https://github.com/jdemeyer",
    "created_at": "2017-04-06T20:26:21Z",
    "event": "reopened",
    "issue": "https://github.com/sagemath/sage/issues/20626",
    "type": "issue_event",
    "url": "https://github.com/sagemath/sage/issues/20626#event-287945"
}

archive/issue_comments_298221.json:

{
    "body": "Changed author from **Jeroen Demeyer** to none",
    "created_at": "2017-04-06T20:26:21Z",
    "formatter": "markdown",
    "issue": "https://github.com/sagemath/sage/issues/20626",
    "type": "issue_comment",
    "url": "https://github.com/sagemath/sage/issues/20626#issuecomment-298221",
    "user": "https://github.com/jdemeyer"
}

Changed author from Jeroen Demeyer to none


archive/issue_comments_298222.json:

{
    "body": "Changed branch from **[u/jdemeyer/ticket/20626](https://github.com/sagemath/sagetrac-mirror/tree/u/jdemeyer/ticket/20626)** to none",
    "created_at": "2017-04-06T20:26:21Z",
    "formatter": "markdown",
    "issue": "https://github.com/sagemath/sage/issues/20626",
    "type": "issue_comment",
    "url": "https://github.com/sagemath/sage/issues/20626#issuecomment-298222",
    "user": "https://github.com/jdemeyer"
}

Changed branch from u/jdemeyer/ticket/20626 to none


archive/issue_events_287946.json:

{
    "actor": "https://github.com/jdemeyer",
    "created_at": "2017-04-06T20:26:21Z",
    "event": "unlabeled",
    "issue": "https://github.com/sagemath/sage/issues/20626",
    "label": "https://github.com/sagemath/sage/labels/wontfix",
    "label_color": "c6c6c6",
    "label_name": "wontfix",
    "label_text_color": "ffffff",
    "type": "issue_event",
    "url": "https://github.com/sagemath/sage/issues/20626#event-287946"
}

archive/issue_comments_298223.json:

{
    "body": "Changed commit from **[`f25a7d7`](https://github.com/sagemath/sagetrac-mirror/commit/f25a7d7416b54f4b7e9fac0fb9c9c50fb10bb0a5)** to none",
    "created_at": "2017-04-06T20:26:21Z",
    "formatter": "markdown",
    "issue": "https://github.com/sagemath/sage/issues/20626",
    "type": "issue_comment",
    "url": "https://github.com/sagemath/sage/issues/20626#issuecomment-298223",
    "user": "https://github.com/jdemeyer"
}

Changed commit from f25a7d7 to none


archive/issue_comments_298224.json:

{
    "body": "Changed dependencies from **#15648** to none",
    "created_at": "2017-04-06T20:26:36Z",
    "formatter": "markdown",
    "issue": "https://github.com/sagemath/sage/issues/20626",
    "type": "issue_comment",
    "url": "https://github.com/sagemath/sage/issues/20626#issuecomment-298224",
    "user": "https://github.com/jdemeyer"
}

Changed dependencies from #15648 to none


archive/issue_comments_298225.json:

{
    "body": "<div id=\"comment:12\" align=\"right\">comment:12</div>\n\nHi Jeroen,\nI am happy to see work happening on this front, but a bit confused by the recent activity. Could you clarify? Thanks!",
    "created_at": "2017-04-07T03:12:31Z",
    "formatter": "markdown",
    "issue": "https://github.com/sagemath/sage/issues/20626",
    "type": "issue_comment",
    "url": "https://github.com/sagemath/sage/issues/20626#issuecomment-298225",
    "user": "https://github.com/nthiery"
}
comment:12

Hi Jeroen, I am happy to see work happening on this front, but a bit confused by the recent activity. Could you clarify? Thanks!


archive/issue_comments_298226.json:

{
    "body": "<div id=\"comment:13\" align=\"right\">comment:13</div>\n\nReplying to [@nthiery](#comment%3A12):\n> Hi Jeroen,\n> I am happy to see work happening on this front, but a bit confused by the recent activity. Could you clarify?\n\nI got quite negative reactions (mostly from Nils Bruin but also from Erik Bray) on #22752, which is a dependency of this ticket and #15648.\n\nSo either\n\n1. Nils and/or Erik need to reimplement lazy imports \"their way\".\n\n2. Nils and/or Erik should realize that my code on #22752 wasn't so bad anyway.\n\n3. We try to fix #15648 and #20626 with the current implementation of lazy imports, without #22752.",
    "created_at": "2017-04-07T07:31:14Z",
    "formatter": "markdown",
    "issue": "https://github.com/sagemath/sage/issues/20626",
    "type": "issue_comment",
    "url": "https://github.com/sagemath/sage/issues/20626#issuecomment-298226",
    "user": "https://github.com/jdemeyer"
}
comment:13

Replying to @nthiery:

Hi Jeroen, I am happy to see work happening on this front, but a bit confused by the recent activity. Could you clarify?

I got quite negative reactions (mostly from Nils Bruin but also from Erik Bray) on #22752, which is a dependency of this ticket and #15648.

So either

  1. Nils and/or Erik need to reimplement lazy imports "their way".

  2. Nils and/or Erik should realize that my code on #22752 wasn't so bad anyway.

  3. We try to fix #15648 and #20626 with the current implementation of lazy imports, without #22752.


archive/issue_comments_298227.json:

{
    "body": "<div id=\"comment:14\" align=\"right\">comment:14</div>\n\nHi there,\nWhile searching for lazy import issues I stumbled back on this ticket. It seems things have evolved a bit since the last comment with #22752 being merged. Does it change the status of this ticket?\n\nCheers,",
    "created_at": "2018-07-22T15:03:31Z",
    "formatter": "markdown",
    "issue": "https://github.com/sagemath/sage/issues/20626",
    "type": "issue_comment",
    "url": "https://github.com/sagemath/sage/issues/20626#issuecomment-298227",
    "user": "https://github.com/nthiery"
}
comment:14

Hi there, While searching for lazy import issues I stumbled back on this ticket. It seems things have evolved a bit since the last comment with #22752 being merged. Does it change the status of this ticket?

Cheers,


archive/issue_events_287947.json:

{
    "actor": "https://github.com/jdemeyer",
    "created_at": "2018-07-22T15:29:11Z",
    "event": "milestoned",
    "issue": "https://github.com/sagemath/sage/issues/20626",
    "milestone_number": null,
    "milestone_title": "sage-8.3",
    "type": "issue_event",
    "url": "https://github.com/sagemath/sage/issues/20626#event-287947"
}

archive/issue_comments_298228.json:

{
    "body": "<div id=\"comment:15\" align=\"right\">comment:15</div>\n\nI am reverting to the ticket description before #22752. Do you still have that \"attached archive containing a trivial module bar lazy imported\"?",
    "created_at": "2018-07-22T15:29:11Z",
    "formatter": "markdown",
    "issue": "https://github.com/sagemath/sage/issues/20626",
    "type": "issue_comment",
    "url": "https://github.com/sagemath/sage/issues/20626#issuecomment-298228",
    "user": "https://github.com/jdemeyer"
}
comment:15

I am reverting to the ticket description before #22752. Do you still have that "attached archive containing a trivial module bar lazy imported"?


archive/issue_comments_298229.json:

{
    "body": "Changed upstream from **Reported upstream. No feedback yet.** to **Fixed upstream, in a later stable release.**",
    "created_at": "2018-07-22T15:29:11Z",
    "formatter": "markdown",
    "issue": "https://github.com/sagemath/sage/issues/20626",
    "type": "issue_comment",
    "url": "https://github.com/sagemath/sage/issues/20626#issuecomment-298229",
    "user": "https://github.com/jdemeyer"
}

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


archive/issue_comments_298230.json:

{
    "body": "Description changed:\n``````diff\n--- \n+++ \n@@ -1,29 +1,31 @@\n-**Steps to reproduce**: apply this patch:\n-\n-```diff\n-diff --git a/src/sage/combinat/__init__.py b/src/sage/combinat/__init__.py\n-index 24242dd..220794c 100644\n---- a/src/sage/combinat/__init__.py\n-+++ b/src/sage/combinat/__init__.py\n-@@ -43,5 +43,9 @@ Related topics\n- - :ref:`sage.graphs`\n- \n- \"\"\"\n--from . import quickref\n--from . import tutorial\n-+\n-+from sage.misc.lazy_import import _lazyimport_\n-+\n-+with _lazyimport_:\n-+    from . import quickref\n-+    from . import tutorial\n-```\n-\n-And run Sage:\n+**Steps to reproduce**: extract the attached archive containing a trivial module bar lazy imported from a module foo in the current directory, and run sage:\n \n ```\n-sage: sage.combinat.tutorial?\n-Segmentation fault\n+sage: import foo\n+sage: foo.bar?\n+---------------------------------------------------------------------------\n+RuntimeError                              Traceback (most recent call last)\n+<ipython-input-2-04fe32111b22> in <module>()\n+----> 1 get_ipython().magic(u'pinfo foo.bar')\n+\n+/opt/sage-git/local/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in magic(self, arg_s)\n+   2161         magic_name, _, magic_arg_s = arg_s.partition(' ')\n+   2162         magic_name = magic_name.lstrip(prefilter.ESC_MAGIC)\n+-> 2163         return self.run_line_magic(magic_name, magic_arg_s)\n+   2164 \n+   2165     #-------------------------------------------------------------------------\n+\n+\n+... last 3 frames repeated, from the frame below ...\n+\n+/opt/sage-git/local/lib/python2.7/site-packages/sage/misc/sageinspect.pyc in sage_getdoc_original(obj)\n+   1765         typ = type(obj)\n+   1766 \n+-> 1767     s,argspec = _extract_embedded_signature(_sage_getdoc_unformatted(obj), typ.__name__)\n+   1768     if s:\n+   1769         pos = _extract_embedded_position(s)\n+\n+RuntimeError: maximum recursion depth exceeded in __instancecheck__\n ```\n \n **Analysis**: sage.misc.sageinspect.sage_getdoc_original gets confused\n``````\n",
    "created_at": "2018-07-22T15:29:11Z",
    "formatter": "markdown",
    "issue": "https://github.com/sagemath/sage/issues/20626",
    "type": "issue_comment",
    "url": "https://github.com/sagemath/sage/issues/20626#issuecomment-298230",
    "user": "https://github.com/jdemeyer"
}

Description changed:

--- 
+++ 
@@ -1,29 +1,31 @@
-**Steps to reproduce**: apply this patch:
-
-```diff
-diff --git a/src/sage/combinat/__init__.py b/src/sage/combinat/__init__.py
-index 24242dd..220794c 100644
---- a/src/sage/combinat/__init__.py
-+++ b/src/sage/combinat/__init__.py
-@@ -43,5 +43,9 @@ Related topics
- - :ref:`sage.graphs`
- 
- """
--from . import quickref
--from . import tutorial
-+
-+from sage.misc.lazy_import import _lazyimport_
-+
-+with _lazyimport_:
-+    from . import quickref
-+    from . import tutorial
-```
-
-And run Sage:
+**Steps to reproduce**: extract the attached archive containing a trivial module bar lazy imported from a module foo in the current directory, and run sage:
 
 ```
-sage: sage.combinat.tutorial?
-Segmentation fault
+sage: import foo
+sage: foo.bar?
+---------------------------------------------------------------------------
+RuntimeError                              Traceback (most recent call last)
+<ipython-input-2-04fe32111b22> in <module>()
+----> 1 get_ipython().magic(u'pinfo foo.bar')
+
+/opt/sage-git/local/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in magic(self, arg_s)
+   2161         magic_name, _, magic_arg_s = arg_s.partition(' ')
+   2162         magic_name = magic_name.lstrip(prefilter.ESC_MAGIC)
+-> 2163         return self.run_line_magic(magic_name, magic_arg_s)
+   2164 
+   2165     #-------------------------------------------------------------------------
+
+
+... last 3 frames repeated, from the frame below ...
+
+/opt/sage-git/local/lib/python2.7/site-packages/sage/misc/sageinspect.pyc in sage_getdoc_original(obj)
+   1765         typ = type(obj)
+   1766 
+-> 1767     s,argspec = _extract_embedded_signature(_sage_getdoc_unformatted(obj), typ.__name__)
+   1768     if s:
+   1769         pos = _extract_embedded_position(s)
+
+RuntimeError: maximum recursion depth exceeded in __instancecheck__
 ```
 
 **Analysis**: sage.misc.sageinspect.sage_getdoc_original gets confused

archive/issue_comments_298231.json:

{
    "body": "<div id=\"comment:16\" align=\"right\">comment:16</div>\n\nupdate milestone 8.3 -> 8.4",
    "created_at": "2018-08-03T19:20:18Z",
    "formatter": "markdown",
    "issue": "https://github.com/sagemath/sage/issues/20626",
    "type": "issue_comment",
    "url": "https://github.com/sagemath/sage/issues/20626#issuecomment-298231",
    "user": "https://github.com/videlec"
}
comment:16

update milestone 8.3 -> 8.4


archive/issue_events_287948.json:

{
    "actor": "https://github.com/videlec",
    "created_at": "2018-08-03T19:20:18Z",
    "event": "demilestoned",
    "issue": "https://github.com/sagemath/sage/issues/20626",
    "milestone_number": null,
    "milestone_title": "sage-8.3",
    "type": "issue_event",
    "url": "https://github.com/sagemath/sage/issues/20626#event-287948"
}

archive/issue_events_287949.json:

{
    "actor": "https://github.com/videlec",
    "created_at": "2018-08-03T19:20:18Z",
    "event": "milestoned",
    "issue": "https://github.com/sagemath/sage/issues/20626",
    "milestone_number": null,
    "milestone_title": "sage-8.4",
    "type": "issue_event",
    "url": "https://github.com/sagemath/sage/issues/20626#event-287949"
}

archive/issue_comments_298232.json:

{
    "body": "<div id=\"comment:17\" align=\"right\">comment:17</div>\n\nPrompted by Sam, I tried to recreate the archive with several variants of:\n\n```\nmkdir -p foo/bar\ntouch foo/bar/__init__.py\ncat > foo/__init.py__ <<EOF\nfrom sage.misc.lazy_import import LazyImport\nbar = LazyImport('foo', 'bar')\nEOF\n```\n\nHowever -- not quite surprisingly -- that fails:\n\n```\nsage                                                                                                                  \n\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n\u2502 SageMath version 9.0, Release Date: 2020-01-01                     \u2502\n\u2502 Using Python 3.7.3. Type \"help()\" for help.                        \u2502\n\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\nsage: import foo\nsage: foo.bar\n------------------------------------------------------------------------\n/opt/sage-git/local/lib/python3.7/site-packages/cysignals/signals.cpython-37m-x86_64-linux-gnu.so(+0x9a64)[0x7f49349d7a64]\n/opt/sage-git/local/lib/python3.7/site-packages/cysignals/signals.cpython-37m-x86_64-linux-gnu.so(+0x9b19)[0x7f49349d7b19]\n/opt/sage-git/local/lib/python3.7/site-packages/cysignals/signals.cpython-37m-x86_64-linux-gnu.so(+0xd57f)[0x7f49349db57f]\n/lib/x86_64-linux-gnu/libc.so.6(+0x46470)[0x7f49373fe470]\n/opt/sage-git/local/lib/libpython3.7m.so.1.0(+0xe2e44)[0x7f49376c8e44]\n/opt/sage-git/local/lib/libpython3.7m.so.1.0(PyUnicode_New+0x8b)[0x7f49376e98fb]\n/opt/sage-git/local/lib/libpython3.7m.so.1.0(_PyUnicodeWriter_PrepareInternal+0x1c1)[0x7f493770fad1]\n```\n\nI can't remember which idiom I had tried back then. Maybe that\nidiom does not exist anymore.\n\nIt would be useful though to have some idiom that enables to lazy\nimport a submodule into a module, making sure that one can indeed\ninspect its documentation.",
    "created_at": "2020-09-19T04:44:05Z",
    "formatter": "markdown",
    "issue": "https://github.com/sagemath/sage/issues/20626",
    "type": "issue_comment",
    "url": "https://github.com/sagemath/sage/issues/20626#issuecomment-298232",
    "user": "https://github.com/nthiery"
}
comment:17

Prompted by Sam, I tried to recreate the archive with several variants of:

mkdir -p foo/bar
touch foo/bar/__init__.py
cat > foo/__init.py__ <<EOF
from sage.misc.lazy_import import LazyImport
bar = LazyImport('foo', 'bar')
EOF

However -- not quite surprisingly -- that fails:

sage                                                                                                                  
┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 9.0, Release Date: 2020-01-01                     │
│ Using Python 3.7.3. Type "help()" for help.                        │
└────────────────────────────────────────────────────────────────────┘
sage: import foo
sage: foo.bar
------------------------------------------------------------------------
/opt/sage-git/local/lib/python3.7/site-packages/cysignals/signals.cpython-37m-x86_64-linux-gnu.so(+0x9a64)[0x7f49349d7a64]
/opt/sage-git/local/lib/python3.7/site-packages/cysignals/signals.cpython-37m-x86_64-linux-gnu.so(+0x9b19)[0x7f49349d7b19]
/opt/sage-git/local/lib/python3.7/site-packages/cysignals/signals.cpython-37m-x86_64-linux-gnu.so(+0xd57f)[0x7f49349db57f]
/lib/x86_64-linux-gnu/libc.so.6(+0x46470)[0x7f49373fe470]
/opt/sage-git/local/lib/libpython3.7m.so.1.0(+0xe2e44)[0x7f49376c8e44]
/opt/sage-git/local/lib/libpython3.7m.so.1.0(PyUnicode_New+0x8b)[0x7f49376e98fb]
/opt/sage-git/local/lib/libpython3.7m.so.1.0(_PyUnicodeWriter_PrepareInternal+0x1c1)[0x7f493770fad1]

I can't remember which idiom I had tried back then. Maybe that idiom does not exist anymore.

It would be useful though to have some idiom that enables to lazy import a submodule into a module, making sure that one can indeed inspect its documentation.


archive/issue_events_287950.json:

{
    "actor": "https://github.com/mkoeppe",
    "created_at": "2022-12-29T01:42:26Z",
    "event": "demilestoned",
    "issue": "https://github.com/sagemath/sage/issues/20626",
    "milestone_number": null,
    "milestone_title": "sage-8.4",
    "type": "issue_event",
    "url": "https://github.com/sagemath/sage/issues/20626#event-287950"
}