-
-
Notifications
You must be signed in to change notification settings - Fork 528
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
py3 failures in sage/misc/sageinspect.py and sagedoc.py #27971
Comments
comment:1
This silences the warnings: diff --git a/src/sage/misc/sageinspect.py b/src/sage/misc/sageinspect.py
index b7571b44f1..e95220ca9a 100644
--- a/src/sage/misc/sageinspect.py
+++ b/src/sage/misc/sageinspect.py
@@ -125,6 +125,7 @@ import os
import sys
import tokenize
import re
+import warnings
EMBEDDED_MODE = False
from sage.env import SAGE_LIB
@@ -1693,7 +1694,12 @@ def sage_getdef(obj, obj_name=''):
"""
try:
spec = sage_getargspec(obj)
- s = str(inspect.formatargspec(*spec))
+ if six.PY3:
+ with warnings.catch_warnings():
+ warnings.simplefilter("ignore")
+ s = str(inspect.formatargspec(*spec))
+ else:
+ s = str(inspect.formatargspec(*spec))
s = s.strip('(').strip(')').strip()
if s[:4] == 'self':
s = s[4:] |
comment:2
Reimplementing diff --git a/src/sage/misc/sageinspect.py b/src/sage/misc/sageinspect.py
index b7571b44f1..e46b9866ed 100644
--- a/src/sage/misc/sageinspect.py
+++ b/src/sage/misc/sageinspect.py
@@ -1658,6 +1658,49 @@ def sage_getargspec(obj):
defaults = None
return inspect.ArgSpec(args, varargs, varkw, defaults)
+def joinseq(seq):
+ if len(seq) == 1:
+ return '(' + seq[0] + ',)'
+ else:
+ return '(' + ', '.join(seq) + ')'
+
+def strseq(object, convert, join=joinseq):
+ """
+ Recursively walk a sequence, stringifying each element.
+ """
+ if type(object) in (list, tuple):
+ return join(map(lambda o, c=convert, j=join: strseq(o, c, j), object))
+ else:
+ return convert(object)
+
+def formatargspec(args, varargs=None, varkw=None, defaults=None,
+ formatarg=str,
+ formatvarargs=lambda name: '*' + name,
+ formatvarkw=lambda name: '**' + name,
+ formatvalue=lambda value: '=' + repr(value),
+ join=joinseq):
+ """
+ Format an argument spec from the 4 values returned by getargspec.
+
+ The first four arguments are (args, varargs, varkw, defaults). The
+ other four arguments are the corresponding optional formatting functions
+ that are called to turn names and values into strings. The ninth
+ argument is an optional function to format the sequence of arguments.
+ """
+ specs = []
+ if defaults:
+ firstdefault = len(args) - len(defaults)
+ for i, arg in enumerate(args):
+ spec = strseq(arg, formatarg, join)
+ if defaults and i >= firstdefault:
+ spec = spec + formatvalue(defaults[i - firstdefault])
+ specs.append(spec)
+ if varargs is not None:
+ specs.append(formatvarargs(varargs))
+ if varkw is not None:
+ specs.append(formatvarkw(varkw))
+ return '(' + ', '.join(specs) + ')'
+
def sage_getdef(obj, obj_name=''):
r"""
@@ -1693,7 +1736,7 @@ def sage_getdef(obj, obj_name=''):
"""
try:
spec = sage_getargspec(obj)
- s = str(inspect.formatargspec(*spec))
+ s = str(formatargspec(*spec))
s = s.strip('(').strip(')').strip()
if s[:4] == 'self':
s = s[4:] (This is taken essentially verbatim from Python 2.7's inspect.py.) |
This comment has been minimized.
This comment has been minimized.
comment:4
As sage has it's own Note: Maybe we should define our own |
comment:5
I don't see anything indicating that
(well, two lines if you count Or we could switch to using
I don't think there is any urgency for either of these. |
Branch: u/jhpalmieri/formatargspec |
Commit: |
Author: John Palmieri |
comment:7
Okay, here is an implementation of New commits:
|
comment:8
It's so nice not to have that
and a few others. Really the stuff of a new ticket but before this branch it was literally impossible to notice that stuff. |
comment:9
Yes, I noticed that, too. Definitely for a different ticket — the issues can be solved completely independently. |
comment:10
Let's not worry about the pyflakes warnings for |
This comment has been minimized.
This comment has been minimized.
comment:11
Ping? |
comment:12
|
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
|
comment:14
Replying to @vinklein:
I modified this. |
Reviewer: Vincent Klein |
comment:15
Looks good to me. |
Changed branch from u/jhpalmieri/formatargspec to |
comment:17
Not in Sage 8.8. Let's please to try keep tickets' milestones related to the release in which we actually intend to include them, and in particular the release in which they were actually included, especially when closing tickets. |
The Python 3 doctest failures in
sage/misc/sageinspect.py
andsage/misc/sagedoc.py
all arise because of the second line here (fromsageinspect.py
):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) forinspect.formatargspec
. The documentation says to usesignature
andSignature
, but we have already obtained the signature information usingsage_getargspec
and just want to format it. Also,inspect.signature
doesn't seem to work on Cython functions — see cython issue 1864, or for a Sage-specific example:At this point, with Python 2:
With Python 3:
Fixing this may also fix #27578.
Component: python3
Author: John Palmieri
Branch/Commit:
bbd5b28
Reviewer: Vincent Klein
Issue created by migration from https://trac.sagemath.org/ticket/27971
The text was updated successfully, but these errors were encountered: