# HG changeset patch
# User Tim Dumol <tim@timdumol.com>
# Date 1256830014 -28800
# Node ID 06cb472606e7355743a79b3bc2fdfc43a01c129d
# Parent d5a514bf7c638a3d3fd5880d57d600978b722cca
#7349 Port of #6848 fixes to SageNB.
diff -r d5a514bf7c63 -r 06cb472606e7 sagenb/misc/sageinspect.py
|
a
|
b
|
|
| 224 | 224 | |
| 225 | 225 | sage: from sage.misc.sageinspect import _sage_getargspec_cython |
| 226 | 226 | sage: _sage_getargspec_cython("def init(self, x=None, base=0):") |
| 227 | | (['self', 'x', 'base'], None, None, ('None', '0')) |
| | 227 | (['self', 'x', 'base'], None, None, (None, 0)) |
| 228 | 228 | sage: _sage_getargspec_cython("def __init__(self, x=None, unsigned int base=0):") |
| 229 | | (['self', 'x', 'base'], None, None, ('None', '0')) |
| | 229 | (['self', 'x', 'base'], None, None, (None, 0)) |
| 230 | 230 | |
| 231 | 231 | AUTHOR: |
| 232 | 232 | |
| … |
… |
|
| 266 | 266 | argnames.append(argname) |
| 267 | 267 | if len(s) > 1: |
| 268 | 268 | defvalue = s[1] |
| 269 | | # Remove quotes around strings |
| 270 | | defvalue = defvalue.strip('"').strip("'") |
| 271 | | argdefs.append(defvalue) |
| | 269 | # eval defvalue so we aren't just returning strings |
| | 270 | argdefs.append(eval(defvalue)) |
| 272 | 271 | |
| 273 | 272 | if len(argdefs) > 0: |
| 274 | 273 | argdefs = tuple(argdefs) |
| … |
… |
|
| 308 | 307 | if isclassinstance(obj): |
| 309 | 308 | return inspect.getabsfile(obj.__class__) |
| 310 | 309 | # No go? fall back to inspect. |
| 311 | | return inspect.getabsfile(obj) |
| | 310 | return inspect.getabsfile(obj) |
| 312 | 311 | |
| 313 | 312 | def sage_getargspec(obj): |
| 314 | 313 | r""" |
| … |
… |
|
| 390 | 389 | sage: sage_getdef(identity_matrix, 'identity_matrix') |
| 391 | 390 | 'identity_matrix(ring, n=0, sparse=False)' |
| 392 | 391 | |
| | 392 | Check that trac #6848 has been fixed: |
| | 393 | |
| | 394 | sage: sage_getdef(RDF.random_element) |
| | 395 | '(min=-1, max=1)' |
| | 396 | |
| 393 | 397 | If an exception is generated, None is returned instead and the |
| 394 | 398 | exception is suppressed. |
| 395 | 399 | |
| … |
… |
|
| 619 | 623 | sage: sage_getsource(sage) |
| 620 | 624 | "...all..." |
| 621 | 625 | |
| 622 | | A cython function with default arguments:: |
| | 626 | A cython function with default arguments (one of which is a string):: |
| 623 | 627 | |
| 624 | 628 | sage: sage_getdef(sage.rings.integer.Integer.factor, obj_name='factor') |
| 625 | | "factor(algorithm='pari', proof='True', limit='None')" |
| | 629 | "factor(algorithm='pari', proof=True, limit=None)" |
| 626 | 630 | |
| 627 | 631 | A cython method without an embedded position can lead to surprising errors:: |
| 628 | 632 | |
| … |
… |
|
| 658 | 662 | Test _sage_getargspec_cython with multiple default arguments and a type:: |
| 659 | 663 | |
| 660 | 664 | sage: _sage_getargspec_cython("def init(self, x=None, base=0):") |
| 661 | | (['self', 'x', 'base'], None, None, ('None', '0')) |
| | 665 | (['self', 'x', 'base'], None, None, (None, 0)) |
| 662 | 666 | sage: _sage_getargspec_cython("def __init__(self, x=None, base=0):") |
| 663 | | (['self', 'x', 'base'], None, None, ('None', '0')) |
| | 667 | (['self', 'x', 'base'], None, None, (None, 0)) |
| 664 | 668 | sage: _sage_getargspec_cython("def __init__(self, x=None, unsigned int base=0):") |
| 665 | | (['self', 'x', 'base'], None, None, ('None', '0')) |
| | 669 | (['self', 'x', 'base'], None, None, (None, 0)) |
| 666 | 670 | |
| 667 | 671 | Test _extract_embedded_position: |
| 668 | 672 | |