Opened 6 months ago

Last modified 5 months ago

#27696 needs_info enhancement

metaticket: py3: deprecate long and __long__, and remove doctesting special-case for long

Reported by: jhpalmieri Owned by:
Priority: major Milestone: sage-wishlist
Component: python3 Keywords:
Cc: Merged in:
Authors: John Palmieri Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Description (last modified by jhpalmieri)

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): 
    23772377        sage: sorted(results.keys())
    23782378        ['cputime', 'err', 'failures', 'optionals', 'tests', 'walltime', 'walltime_skips']
    23792379    """
    2380 
    2381     if six.PY2:
    2382         extra_globals = {}
    2383     else:
    2384         extra_globals = {'long': int}
     2380    extra_globals = {}
    23852381    """
    23862382    Extra objects to place in the global namespace in which tests are run.
    23872383    Normally this should be empty but there are special cases where it may
    23882384    be useful.
    2389 
    2390     In particular, on Python 3 add ``long`` as an alias for ``int`` so that
    2391     tests that use the ``long`` built-in (of which there are many) still pass.
    2392     We do this so that the test suite can run on Python 3 while Python 2 is
    2393     still the default.
    23942385    """
    23952386
    23962387    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 (10)

comment:1 Changed 6 months ago by jhpalmieri

  • Branch set to u/jhpalmieri/long

comment:2 Changed 6 months ago by jhpalmieri

  • Commit set to 1926330cef43d39abea83a701328143b31254705
  • Status changed from new to needs_review

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:

1926330trac 27696: first steps in deprecating long and __long__

comment:3 Changed 5 months ago by embray

  • Milestone changed from sage-8.8 to sage-pending
  • 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 follow-up: Changed 5 months ago by jhpalmieri

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 ; follow-up: Changed 5 months ago by embray

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 5 months ago by jhpalmieri

  • Branch u/jhpalmieri/long deleted
  • Commit 1926330cef43d39abea83a701328143b31254705 deleted
  • Description modified (diff)
  • Milestone changed from sage-pending to sage-wishlist
  • Status changed from needs_work to needs_info
  • Summary changed from py3: deprecate long and __long__, and remove doctesting special-case for long to metaticket: py3: deprecate long and __long__, and remove doctesting special-case for long

comment:7 Changed 5 months ago by jhpalmieri

  • Description modified (diff)

comment:8 Changed 5 months ago by jhpalmieri

  • Description modified (diff)

comment:9 in reply to: ↑ 5 Changed 5 months ago by jdemeyer

Replying to embray:

However, I do like the idea of adding deprecation warnings to __long__.

I disagree, we shouldn't deprecate __long__, it's a standard Python feature. But let's discuss at #27826.

comment:10 Changed 5 months ago by jdemeyer

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.

Note: See TracTickets for help on using tickets.