Ticket #14767: trac_14767.patch

File trac_14767.patch, 1.3 KB (added by Vincent Delecroix, 9 years ago)
  • sage/misc/dev_tools.py

    # HG changeset patch
    # User Vincent Delecroix <20100.delecroix at gmail.com>
    # Date 1372096469 -7200
    # Node ID 73d8c2c659f3a16698467e664923a124cc291d13
    # Parent  ec6a3e8365f9c930df8da62874d84f198ad59ca4
    trac 14767: fix import_statements for lazy imported objects
    
    diff --git a/sage/misc/dev_tools.py b/sage/misc/dev_tools.py
    a b  
    197197        Traceback (most recent call last):
    198198        ...
    199199        ValueError: no import statement for 5
     200
     201    We test that it behaves well with lazy imported objects (:trac:`14767`)::
     202
     203        sage: import_statements(NN)
     204        from sage.rings.semirings.non_negative_integer_semiring import NN
     205        sage: import_statements('NN')
     206        from sage.rings.semirings.non_negative_integer_semiring import NN
    200207    """
    201208    import inspect, sys, re
    202209    import sage.all
    203210    from sage.misc import sageinspect
    204211    from sage.misc.flatten import flatten
     212    from sage.misc.lazy_import import LazyImport
    205213
    206214    lazy = options.get("lazy", False)
    207215    verbose = options.get("verbose", True)
     
    224232        else:
    225233            name = None
    226234
     235        if isinstance(obj, LazyImport):
     236            obj = obj._get_object()
     237
    227238        # Case 1: the object is a module
    228239        if inspect.ismodule(obj):
    229240            if lazy: