Changes between Version 3 and Version 11 of Ticket #27971


Ignore:
Timestamp:
06/18/19 04:06:32 (2 years ago)
Author:
jhpalmieri
Comment:

Ping?

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #27971

    • Property Status changed from new to needs_review
    • Property Commit changed from to 56516cf95b775ffab3e6e85fd7c9c78ded927251
    • Property Branch changed from to u/jhpalmieri/formatargspec
    • Property Authors changed from to John Palmieri
  • Ticket #27971 – Description

    v3 v11  
    44        s = str(inspect.formatargspec(*spec))
    55}}}
    6 The problem is that `inspect.formatargspec` is deprecated in Python 3.5, so it prints warning messages. From Sage's point of view, this is annoying, because there is no direct replacement (as far as I can tell) for `inspect.formatargspec`. The [https://docs.python.org/3/library/inspect.html#inspect.formatargspec documentation] says to use `signature` and `Signature`, but we have already obtained the signature information using `sage_getargspec` and just want to format it. Also, `inspect.signature` doesn't seem to work on Cython functions (See cython [https://github.com/cython/cython/issues/1864 issue 1864]).
     6The problem is that `inspect.formatargspec` is deprecated in Python 3.5, so it prints warning messages. From Sage's point of view, this is annoying, because there is no direct replacement (as far as I can tell) for `inspect.formatargspec`. The [https://docs.python.org/3/library/inspect.html#inspect.formatargspec documentation] says to use `signature` and `Signature`, but we have already obtained the signature information using `sage_getargspec` and just want to format it. Also, `inspect.signature` doesn't seem to work on Cython functions — see cython [https://github.com/cython/cython/issues/1864 issue 1864], or for a Sage-specific example:
     7{{{
     8sage: import inspect
     9sage: from sage.misc.sageinspect import sage_getargspec
     10sage: from sage.rings.integer import int_to_Z
     11sage: sage_getargspec(int_to_Z)
     12ArgSpec(args=['self', 'x'], varargs='args', keywords='kwds', defaults=None)
     13}}}
     14At this point, with Python 2:
     15{{{
     16sage: inspect.getargspec(long_to_Z)
     17...
     18TypeError: <type 'sage.rings.integer.long_to_Z'> is not a Python function
     19}}}
     20With Python 3:
     21{{{
     22sage: inspect.signature(int_to_Z)
     23...
     24ValueError: no signature found for builtin type <class 'sage.rings.integer.int_to_Z'>
     25}}}
    726
    8 #27578 is related, by the way.
    9 
    10 One short-term option is to silence the warnings. Another option is to just reimplement the `formatargspec` function: it's  about 15 lines long, just string manipulation.
     27Fixing this may also fix #27578.