Opened 19 months ago
Closed 2 months ago
#27696 closed enhancement (invalid)
metaticket: py3: deprecate long and __long__, and remove doctesting specialcase for long
Reported by:  jhpalmieri  Owned by:  

Priority:  major  Milestone:  sageduplicate/invalid/wontfix 
Component:  python3  Keywords:  
Cc:  mkoeppe  Merged in:  
Authors:  John Palmieri  Reviewers:  
Report Upstream:  N/A  Work issues:  
Branch:  Commit:  
Dependencies:  Stopgaps: 
Description (last modified by )
The overarching goal of this ticket is to make this change:

src/sage/doctest/forker.py
diff git a/src/sage/doctest/forker.py b/src/sage/doctest/forker.py index 4b222dd1db..d97034090f 100644
a b class DocTestTask(object): 2377 2377 sage: sorted(results.keys()) 2378 2378 ['cputime', 'err', 'failures', 'optionals', 'tests', 'walltime', 'walltime_skips'] 2379 2379 """ 2380 2381 if six.PY2: 2382 extra_globals = {} 2383 else: 2384 extra_globals = {'long': int} 2380 extra_globals = {} 2385 2381 """ 2386 2382 Extra objects to place in the global namespace in which tests are run. 2387 2383 Normally this should be empty but there are special cases where it may 2388 2384 be useful. 2389 2390 In particular, on Python 3 add ``long`` as an alias for ``int`` so that2391 tests that use the ``long`` builtin (of which there are many) still pass.2392 We do this so that the test suite can run on Python 3 while Python 2 is2393 still the default.2394 2385 """ 2395 2386 2396 2387 def __init__(self, source):
With Python 3 doctesting, long
has been automatically converted to int
. It would be better to not have such a big difference in the behavior of doctesting vs. ordinary Sage usage: with Python 3, evaluating long(3)
would fail at the command line but work in doctesting.
First we should deprecate __long__
methods for Sage classes, and we should also designate doctests involving long(...)
as being py2
only. Once enough of those tasks have been complete, we can make this change to the doctesting framework.
See #27826 for a collection of deprecations. This is not complete: that ticket does not deprecate __long__
for integers and rational numbers.
See #27829 for marking some doctests with # py2
.
Change History (14)
comment:1 Changed 19 months ago by
 Branch set to u/jhpalmieri/long
comment:2 Changed 19 months ago by
 Commit set to 1926330cef43d39abea83a701328143b31254705
 Status changed from new to needs_review
comment:3 Changed 18 months ago by
 Milestone changed from sage8.8 to sagepending
 Status changed from needs_review to needs_work
This was done this way very intentionally in #24559, in large part to avoid such a massive patch like this.
It would be better I think to wait until Python 2 support is dropped completely.
comment:4 followup: ↓ 5 Changed 18 months ago by
Right, but that was a year ago. I see no reason to wait until Python 2 support is dropped completely, although if you prefer, we can do this incrementally: say, first add # py2
to a bunch of doctests of the form
sage: long(blah)
We should also deprecate __long__
for various classes. When the appropriate pieces are in place, turn off the conversion long > int
in Python 3 doctesting.
The current situation is very misleading, where a doctest will pass with Python 3 but the same code will fail if run by hand.
comment:5 in reply to: ↑ 4 ; followup: ↓ 9 Changed 18 months ago by
Replying to jhpalmieri:
The current situation is very misleading, where a doctest will pass with Python 3 but the same code will fail if run by hand.
There are many cases like that where the doctests don't work quite the same on Python 3 but in mostly trivial ways which are made transparent by the doctest framework. I think that's ok, personally.
However, I do like the idea of adding deprecation warnings to __long__
. What if as a middle ground we started with just that part?
comment:6 Changed 18 months ago by
 Branch u/jhpalmieri/long deleted
 Commit 1926330cef43d39abea83a701328143b31254705 deleted
 Description modified (diff)
 Milestone changed from sagepending to sagewishlist
 Status changed from needs_work to needs_info
 Summary changed from py3: deprecate long and __long__, and remove doctesting specialcase for long to metaticket: py3: deprecate long and __long__, and remove doctesting specialcase for long
comment:7 Changed 18 months ago by
 Description modified (diff)
comment:8 Changed 18 months ago by
 Description modified (diff)
comment:9 in reply to: ↑ 5 Changed 18 months ago by
comment:10 Changed 18 months ago by
Also, I don't see how deprecating __long__
helps to achieve the goal of this ticket. Adding the # py2
flags to all doctests involving long(...)
should be sufficient.
comment:11 Changed 6 months ago by
comment:12 Changed 2 months ago by
 Cc mkoeppe added
 Milestone changed from sagewishlist to sageduplicate/invalid/wontfix
 Status changed from needs_info to needs_review
shall we close this one too ?
comment:14 Changed 2 months ago by
 Resolution set to invalid
 Status changed from positive_review to closed
There are a few places where there should be deprecations but there are not: in rational.pyx and integer.pyx, deprecations lead to deprecations warnings all over the place in the Sage library. In
complex_double.pyx
, for example, the__long__
method just raises an error, and it seemed that deprecating such a method has no effect: the deprecation warning is not printed, just the error is.New commits:
trac 27696: first steps in deprecating long and __long__