Skip to content

Commit 20095b7

Browse files
author
Release Manager
committed
Trac #32951: remove some py2 or py3 tags in doctests
after #32793 URL: https://trac.sagemath.org/32951 Reported by: chapoton Ticket author(s): Frédéric Chapoton Reviewer(s): Michael Orlitzky
2 parents e55a915 + b51e43c commit 20095b7

File tree

8 files changed

+25
-83
lines changed

8 files changed

+25
-83
lines changed

src/sage/cpython/getattr.pyx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,6 @@ cpdef getattr_from_other_class(self, cls, name):
310310
311311
sage: "__weakref__" in dir(A)
312312
True
313-
sage: "__weakref__" in dir(1) # py2
314-
False
315313
sage: 1.__weakref__
316314
Traceback (most recent call last):
317315
...

src/sage/docs/instancedoc.pyx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -312,11 +312,7 @@ def instancedoc(cls):
312312
TypeError: expected type, got 7
313313
314314
sage: class OldStyle: pass
315-
sage: instancedoc(OldStyle) # py2
316-
Traceback (most recent call last):
317-
...
318-
TypeError: expected type, got <class __main__.OldStyle at ...>
319-
sage: instancedoc(OldStyle) # py3
315+
sage: instancedoc(OldStyle)
320316
Traceback (most recent call last):
321317
...
322318
TypeError: instancedoc requires <class '__main__.OldStyle'> to have an '_instancedoc_' attribute

src/sage/ext/fast_callable.pyx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,9 +372,7 @@ def fast_callable(x, domain=None, vars=None,
372372
sage: K.<x,y,z> = QQ[]
373373
sage: p = x*y^2 + 1/3*y^2 - x*z - y*z
374374
sage: fp = fast_callable(p, domain=RDF)
375-
sage: fp.op_list() # py2
376-
[('load_const', 0.0), ('load_const', -1.0), ('load_arg', 0), ('ipow', 1), ('load_arg', 2), ('ipow', 1), 'mul', 'mul', 'add', ('load_const', 1.0), ('load_arg', 0), ('ipow', 1), ('load_arg', 1), ('ipow', 2), 'mul', 'mul', 'add', ('load_const', 0.3333333333333333), ('load_arg', 1), ('ipow', 2), 'mul', 'add', ('load_const', -1.0), ('load_arg', 1), ('ipow', 1), ('load_arg', 2), ('ipow', 1), 'mul', 'mul', 'add', 'return']
377-
sage: fp.op_list() # py3
375+
sage: fp.op_list()
378376
[('load_const', 0.0), ('load_const', 1.0), ('load_arg', 0), ('ipow', 1), ('load_arg', 1), ('ipow', 2), 'mul', 'mul', 'add', ('load_const', 0.3333333333333333), ('load_arg', 1), ('ipow', 2), 'mul', 'add', ('load_const', -1.0), ('load_arg', 0), ('ipow', 1), ('load_arg', 2), ('ipow', 1), 'mul', 'mul', 'add', ('load_const', -1.0), ('load_arg', 1), ('ipow', 1), ('load_arg', 2), ('ipow', 1), 'mul', 'mul', 'add', 'return']
379377
sage: fp(e, pi, sqrt(2)) # abs tol 3e-14
380378
21.831120464939584

src/sage/misc/sageinspect.py

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -521,15 +521,14 @@ def visit_NameConstant(self, node):
521521
522522
EXAMPLES::
523523
524-
sage: import ast, sage.misc.sageinspect as sms # py3
525-
sage: visitor = sms.SageArgSpecVisitor() # py3
526-
sage: vis = lambda x: visitor.visit_NameConstant(ast.parse(x).body[0].value) # py3
527-
sage: [vis(n) for n in ['True', 'False', 'None']] # py3
524+
sage: import ast, sage.misc.sageinspect as sms
525+
sage: visitor = sms.SageArgSpecVisitor()
526+
sage: vis = lambda x: visitor.visit_NameConstant(ast.parse(x).body[0].value)
527+
sage: [vis(n) for n in ['True', 'False', 'None']]
528528
[True, False, None]
529-
sage: [type(vis(n)) for n in ['True', 'False', 'None']] # py3
529+
sage: [type(vis(n)) for n in ['True', 'False', 'None']]
530530
[<class 'bool'>, <class 'bool'>, <class 'NoneType'>]
531531
"""
532-
533532
return node.value
534533

535534
def visit_arg(self, node):
@@ -552,11 +551,11 @@ def visit_arg(self, node):
552551
553552
EXAMPLES::
554553
555-
sage: import ast, sage.misc.sageinspect as sms # py3
556-
sage: s = "def f(a, b=2, c={'a': [4, 5.5, False]}, d=(None, True)):\n return" # py3
557-
sage: visitor = sms.SageArgSpecVisitor() # py3
558-
sage: args = ast.parse(s).body[0].args.args # py3
559-
sage: [visitor.visit_arg(n) for n in args] # py3
554+
sage: import ast, sage.misc.sageinspect as sms
555+
sage: s = "def f(a, b=2, c={'a': [4, 5.5, False]}, d=(None, True)):\n return"
556+
sage: visitor = sms.SageArgSpecVisitor()
557+
sage: args = ast.parse(s).body[0].args.args
558+
sage: [visitor.visit_arg(n) for n in args]
560559
['a', 'b', 'c', 'd']
561560
"""
562561
return node.arg
@@ -1570,10 +1569,6 @@ def foo(x, a='\')"', b={not (2+1==3):'bar'}): return
15701569
inspect module does)::
15711570
15721571
sage: import inspect
1573-
sage: inspect.getargspec(range) # py2
1574-
Traceback (most recent call last):
1575-
...
1576-
TypeError: <built-in function range> is not a Python function
15771572
sage: sage_getargspec(range)
15781573
ArgSpec(args=[], varargs='args', keywords='kwds', defaults=None)
15791574
@@ -1704,28 +1699,28 @@ def formatannotation(annotation, base_module=None):
17041699
17051700
sage: from sage.misc.sageinspect import formatannotation
17061701
sage: import inspect
1707-
sage: def foo(a, *, b:int, **kwargs): # py3
1702+
sage: def foo(a, *, b:int, **kwargs):
17081703
....: pass
1709-
sage: s = inspect.signature(foo) # py3
1704+
sage: s = inspect.signature(foo)
17101705
1711-
sage: a = s.parameters['a'].annotation # py3
1712-
sage: a # py3
1706+
sage: a = s.parameters['a'].annotation
1707+
sage: a
17131708
<class 'inspect._empty'>
1714-
sage: formatannotation(a) # py3
1709+
sage: formatannotation(a)
17151710
'inspect._empty'
17161711
1717-
sage: b = s.parameters['b'].annotation # py3
1718-
sage: b # py3
1712+
sage: b = s.parameters['b'].annotation
1713+
sage: b
17191714
<class 'int'>
1720-
sage: formatannotation(b) # py3
1715+
sage: formatannotation(b)
17211716
'int'
17221717
"""
17231718
if getattr(annotation, '__module__', None) == 'typing':
17241719
return repr(annotation).replace('typing.', '')
17251720
if isinstance(annotation, type):
17261721
if annotation.__module__ in ('builtins', base_module):
17271722
return annotation.__qualname__
1728-
return annotation.__module__+'.'+annotation.__qualname__
1723+
return annotation.__module__ + '.' + annotation.__qualname__
17291724
return repr(annotation)
17301725

17311726

src/sage/rings/integer.pyx

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,20 +1193,9 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement):
11931193
10
11941194
sage: print(Integer(16938402384092843092843098243).hex())
11951195
36bb1e3929d1a8fe2802f083
1196-
1197-
sage: hex(Integer(16)) # py2
1198-
doctest:warning...:
1199-
DeprecationWarning: use the method .hex instead
1200-
See https://trac.sagemath.org/26756 for details.
1201-
'10'
12021196
"""
12031197
return self.str(16)
12041198

1205-
def __hex__(self):
1206-
from sage.misc.superseded import deprecation_cython as deprecation
1207-
deprecation(26756, 'use the method .hex instead')
1208-
return self.hex()
1209-
12101199
def oct(self):
12111200
r"""
12121201
Return the digits of ``self`` in base 8.
@@ -1233,34 +1222,20 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement):
12331222
sage: print(Integer(16938402384092843092843098243).oct())
12341223
15535436162247215217705000570203
12351224
1236-
Behavior of Sage integers vs. Python integers (Python 2 and Python 3)::
1225+
Behavior of Sage integers vs. Python integers::
12371226
12381227
sage: Integer(10).oct()
12391228
'12'
1240-
sage: oct(Integer(10)) # py2
1241-
doctest:warning...:
1242-
DeprecationWarning: use the method .oct instead
1243-
See https://trac.sagemath.org/26756 for details.
1244-
'12'
1245-
sage: oct(int(10)) # py2
1246-
'012'
1247-
sage: oct(int(10)) # py3
1229+
sage: oct(int(10))
12481230
'0o12'
12491231
12501232
sage: Integer(-23).oct()
12511233
'-27'
1252-
sage: oct(int(-23)) # py2
1253-
'-027'
1254-
sage: oct(int(-23)) # py3
1234+
sage: oct(int(-23))
12551235
'-0o27'
12561236
"""
12571237
return self.str(8)
12581238

1259-
def __oct__(self):
1260-
from sage.misc.superseded import deprecation_cython as deprecation
1261-
deprecation(26756, 'use the method .oct instead')
1262-
return self.oct()
1263-
12641239
def binary(self):
12651240
"""
12661241
Return the binary digits of ``self`` as a string.

src/sage/rings/polynomial/polydict.pyx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,7 @@ cdef class PolyDict:
174174
sage: p2 = PolyDict({(0,): 2})
175175
sage: p1 == p2
176176
False
177-
sage: p1 < p2 # py2 - random
178-
False
179-
sage: p1 < p2 # py3
177+
sage: p1 < p2
180178
Traceback (most recent call last):
181179
...
182180
TypeError: '<' not supported between instances of

src/sage/rings/rational.pyx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4221,12 +4221,7 @@ cdef class int_to_Q(Morphism):
42214221
sage: f = sage.rings.rational.int_to_Q()
42224222
sage: f(int(4)) # indirect doctest
42234223
4
4224-
sage: f(4^100) # py2 - this will crash on Python 3
4225-
Traceback (most recent call last):
4226-
...
4227-
TypeError: must be a Python int object
42284224
"""
4229-
42304225
cdef Rational rat
42314226

42324227
if type(a) is not int:

src/sage/rings/real_mpfr.pyx

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2168,19 +2168,6 @@ cdef class RealNumber(sage.structure.element.RingElement):
21682168
mpfr_free_str(s)
21692169
return t
21702170

2171-
def __hex__(self):
2172-
"""
2173-
TESTS::
2174-
2175-
sage: hex(RR(-1/3)) # py2
2176-
doctest:...:
2177-
DeprecationWarning: use the method .hex instead
2178-
See http://trac.sagemath.org/24568 for details.
2179-
'-0x5.5555555555554p-4'
2180-
"""
2181-
deprecation(24568, 'use the method .hex instead')
2182-
return self.hex()
2183-
21842171
def __copy__(self):
21852172
"""
21862173
Return copy of ``self`` - since ``self`` is immutable, we just return

0 commit comments

Comments
 (0)