Ticket #12958: trac_12958-sage_inspect_for_classes-nt.patch

File trac_12958-sage_inspect_for_classes-nt.patch, 1.6 KB (added by nthiery, 11 years ago)
  • sage/misc/sageinspect.py

    # HG changeset patch
    # User Nicolas M. Thiery <nthiery@users.sf.net>
    # Date 1337236862 14400
    # Node ID bd289761d99e5cf1c017f9db7ea1bc075096a390
    # Parent  fcb09ca673c396d3d98d51d6734a65d287231f1f
    #12958: Fix sageinspect to better support old-style classes
    
    diff --git a/sage/misc/sageinspect.py b/sage/misc/sageinspect.py
    a b def sage_getsourcelines(obj, is_binary=F 
    13771377          '    cpdef object pyobject(self):\n',
    13781378        ...
    13791379          '        return self / x\n'], ...)
    1380        
     1380
     1381    TESTS:
     1382
     1383    After #12958, old and new style classes are treated equivalently
     1384    when not found::
     1385
     1386        sage: class Foo: pass
     1387        sage: sage_getsourcelines(Foo)
     1388        Traceback (most recent call last):
     1389        ...
     1390        IOError: could not find class definition
     1391
     1392    However :func:`sage_getsourcelines` (in fact
     1393    :func:`inspect.findsource`) still fails on nested classes::
     1394
     1395        sage: import inspect
     1396        sage: inspect.findsource(Sets.ParentMethods)
     1397        Traceback (most recent call last):
     1398        ...
     1399        IOError: could not find class definition
    13811400
    13821401    AUTHORS:
    1383    
     1402
    13841403    - William Stein
    13851404    - Extensions by Nick Alexander
    13861405    - Extension to interactive Cython code by Simon King
    def sage_getsourcelines(obj, is_binary=F 
    14131432            try:
    14141433                return inspect.getsourcelines(obj)
    14151434            except IOError:
    1416                 if obj.__class__ != type:
     1435                if not inspect.isclass(obj):
    14171436                    return sage_getsourcelines(obj.__class__)
    14181437                raise
    14191438