# 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 |
1377 | 1377 | ' cpdef object pyobject(self):\n', |
1378 | 1378 | ... |
1379 | 1379 | ' 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 |
1381 | 1400 | |
1382 | 1401 | AUTHORS: |
1383 | | |
| 1402 | |
1384 | 1403 | - William Stein |
1385 | 1404 | - Extensions by Nick Alexander |
1386 | 1405 | - Extension to interactive Cython code by Simon King |
… |
… |
def sage_getsourcelines(obj, is_binary=F |
1413 | 1432 | try: |
1414 | 1433 | return inspect.getsourcelines(obj) |
1415 | 1434 | except IOError: |
1416 | | if obj.__class__ != type: |
| 1435 | if not inspect.isclass(obj): |
1417 | 1436 | return sage_getsourcelines(obj.__class__) |
1418 | 1437 | raise |
1419 | 1438 | |