Skip to content
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

Remove calls to 'long(...)', etc. #27826

Closed
jhpalmieri opened this issue May 13, 2019 · 54 comments
Closed

Remove calls to 'long(...)', etc. #27826

jhpalmieri opened this issue May 13, 2019 · 54 comments

Comments

@jhpalmieri
Copy link
Member

long(...) is not defined in Python 3, and so we should remove all calls to long. We should also delete all methods __long__, and remove the special-casing for long in Python 3 doctesting (in doctest/forker.py).

Sage 9.2 will not support Python 2 anymore, so that is this ticket's target release.

CC: @embray @fchapoton

Component: python3

Work Issues: Rebase

Author: John Palmieri

Branch/Commit: 3fcba90

Reviewer: Matthias Koeppe

Issue created by migration from https://trac.sagemath.org/ticket/27826

@jhpalmieri jhpalmieri added this to the sage-8.8 milestone May 13, 2019
@jhpalmieri
Copy link
Member Author

Branch: u/jhpalmieri/deprecate-long

@jhpalmieri
Copy link
Member Author

Commit: d5fcb32

@jhpalmieri
Copy link
Member Author

New commits:

d5fcb32trac 27826: deprecate `__long__` methods for many Sage classes

@jdemeyer
Copy link

Replying to @jhpalmieri:

Notable classes which are not included: integers and rational numbers. This is mainly because those classes are used in so many places in the Sage library that deprecation warnings for them would get triggered many times during doctesting.

Are there really that many places where an integer/rational is explicitly converted to a long? That worries me. I really want to understand better why you're not applying this everywhere (needs_info for that reason).

About the patch itself:

  1. in src/sage/libs/mpmath/ext_main.pyx you messed up the spacing of """

  2. I don't understand the comment This is deprecated, but the ``TypeError`` takes precedence over the deprecation warning when this is run. How does the error "take precedence" over the warning, what are you trying to say?

@jhpalmieri
Copy link
Member Author

comment:4

Regarding integer/rational: if I add deprecation warnings to those, I get over 800 files with failures. Many involve set_random_seed or other uses of randomization:

sage -t --long src/sage/parallel/reference.py
**********************************************************************
File "src/sage/parallel/reference.py", line 34, in sage.parallel.reference.parallel_iter
Failed example:
    set_random_seed(0)
Expected nothing
Got:
    doctest:warning
      File "/Users/jpalmier/Desktop/Sage/git/sage/src/bin/sage-runtests", line 179, in <module>
        err = DC.run()
      File "/Users/jpalmier/Desktop/Sage/git/sage/local/lib/python2.7/site-packages/sage/doctest/control.py", line 1232, in run
        self.run_doctests()
      File "/Users/jpalmier/Desktop/Sage/git/sage/local/lib/python2.7/site-packages/sage/doctest/control.py", line 933, in run_doctests
        self.dispatcher.dispatch()
      File "/Users/jpalmier/Desktop/Sage/git/sage/local/lib/python2.7/site-packages/sage/doctest/forker.py", line 2000, in dispatch
        self.parallel_dispatch()
      File "/Users/jpalmier/Desktop/Sage/git/sage/local/lib/python2.7/site-packages/sage/doctest/forker.py", line 1897, in parallel_dispatch
        w.start()  # This might take some time
      File "/Users/jpalmier/Desktop/Sage/git/sage/local/lib/python2.7/site-packages/sage/doctest/forker.py", line 2183, in start
        super(DocTestWorker, self).start()
      File "/Users/jpalmier/Desktop/Sage/git/sage/local/lib/python2.7/multiprocessing/process.py", line 130, in start
        self._popen = Popen(self)
      File "/Users/jpalmier/Desktop/Sage/git/sage/local/lib/python2.7/multiprocessing/forking.py", line 126, in __init__
        code = process_obj._bootstrap()
      File "/Users/jpalmier/Desktop/Sage/git/sage/local/lib/python2.7/multiprocessing/process.py", line 267, in _bootstrap
        self.run()
      File "/Users/jpalmier/Desktop/Sage/git/sage/local/lib/python2.7/site-packages/sage/doctest/forker.py", line 2139, in run
        task(self.options, self.outtmpfile, msgpipe, self.result_queue)
      File "/Users/jpalmier/Desktop/Sage/git/sage/local/lib/python2.7/site-packages/sage/doctest/forker.py", line 2477, in __call__
        doctests, extras = self._run(runner, options, results)
      File "/Users/jpalmier/Desktop/Sage/git/sage/local/lib/python2.7/site-packages/sage/doctest/forker.py", line 2526, in _run
        result = runner.run(test)
      File "/Users/jpalmier/Desktop/Sage/git/sage/local/lib/python2.7/site-packages/sage/doctest/forker.py", line 869, in run
        return self._run(test, compileflags, out)
      File "/Users/jpalmier/Desktop/Sage/git/sage/local/lib/python2.7/site-packages/sage/doctest/forker.py", line 671, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/Users/jpalmier/Desktop/Sage/git/sage/local/lib/python2.7/site-packages/sage/doctest/forker.py", line 1095, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage.parallel.reference.parallel_iter[2]>", line 1, in <module>
        set_random_seed(Integer(0))
      File "/Users/jpalmier/Desktop/Sage/git/sage/local/lib/python2.7/site-packages/sage/misc/superseded.py", line 102, in deprecation
        warning(trac_number, message, DeprecationWarning, stacklevel)
      File "/Users/jpalmier/Desktop/Sage/git/sage/local/lib/python2.7/site-packages/sage/misc/superseded.py", line 148, in warning
        warn(message, warning_class, stacklevel)
    :
    DeprecationWarning: use of long is deprecated, since long() will no longer be supported in Python 3
    See https://trac.sagemath.org/27826 for details.
**********************************************************************

An example without randomness:

sage -t --long src/sage/quadratic_forms/extras.py
**********************************************************************
File "src/sage/quadratic_forms/extras.py", line 50, in sage.quadratic_forms.extras.is_triangular_number
Failed example:
    F1 = [n for n in range(1,100*(100+1)/2)
          if is_triangular_number(n)]
Expected nothing
Got:
    doctest:warning
      File "/Users/jpalmier/Desktop/Sage/git/sage/src/bin/sage-runtests", line 179, in <module>
        err = DC.run()
      File "/Users/jpalmier/Desktop/Sage/git/sage/local/lib/python2.7/site-packages/sage/doctest/control.py", line 1232, in run
        self.run_doctests()
      File "/Users/jpalmier/Desktop/Sage/git/sage/local/lib/python2.7/site-packages/sage/doctest/control.py", line 933, in run_doctests
        self.dispatcher.dispatch()
      File "/Users/jpalmier/Desktop/Sage/git/sage/local/lib/python2.7/site-packages/sage/doctest/forker.py", line 2000, in dispatch
        self.parallel_dispatch()
      File "/Users/jpalmier/Desktop/Sage/git/sage/local/lib/python2.7/site-packages/sage/doctest/forker.py", line 1897, in parallel_dispatch
        w.start()  # This might take some time
      File "/Users/jpalmier/Desktop/Sage/git/sage/local/lib/python2.7/site-packages/sage/doctest/forker.py", line 2183, in start
        super(DocTestWorker, self).start()
      File "/Users/jpalmier/Desktop/Sage/git/sage/local/lib/python2.7/multiprocessing/process.py", line 130, in start
        self._popen = Popen(self)
      File "/Users/jpalmier/Desktop/Sage/git/sage/local/lib/python2.7/multiprocessing/forking.py", line 126, in __init__
        code = process_obj._bootstrap()
      File "/Users/jpalmier/Desktop/Sage/git/sage/local/lib/python2.7/multiprocessing/process.py", line 267, in _bootstrap
        self.run()
      File "/Users/jpalmier/Desktop/Sage/git/sage/local/lib/python2.7/site-packages/sage/doctest/forker.py", line 2139, in run
        task(self.options, self.outtmpfile, msgpipe, self.result_queue)
      File "/Users/jpalmier/Desktop/Sage/git/sage/local/lib/python2.7/site-packages/sage/doctest/forker.py", line 2477, in __call__
        doctests, extras = self._run(runner, options, results)
      File "/Users/jpalmier/Desktop/Sage/git/sage/local/lib/python2.7/site-packages/sage/doctest/forker.py", line 2526, in _run
        result = runner.run(test)
      File "/Users/jpalmier/Desktop/Sage/git/sage/local/lib/python2.7/site-packages/sage/doctest/forker.py", line 869, in run
        return self._run(test, compileflags, out)
      File "/Users/jpalmier/Desktop/Sage/git/sage/local/lib/python2.7/site-packages/sage/doctest/forker.py", line 671, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/Users/jpalmier/Desktop/Sage/git/sage/local/lib/python2.7/site-packages/sage/doctest/forker.py", line 1095, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage.quadratic_forms.extras.is_triangular_number[7]>", line 1, in <module>
        F1 = [n for n in range(Integer(1),Integer(100)*(Integer(100)+Integer(1))/Integer(2))
      File "/Users/jpalmier/Desktop/Sage/git/sage/local/lib/python2.7/site-packages/sage/misc/superseded.py", line 102, in deprecation
        warning(trac_number, message, DeprecationWarning, stacklevel)
      File "/Users/jpalmier/Desktop/Sage/git/sage/local/lib/python2.7/site-packages/sage/misc/superseded.py", line 148, in warning
        warn(message, warning_class, stacklevel)
    :
    DeprecationWarning: use of long is deprecated, since long() will no longer be supported in Python 3
    See https://trac.sagemath.org/27826 for details.

@jhpalmieri
Copy link
Member Author

comment:5

Replying to @jdemeyer:

About the patch itself:

  1. in src/sage/libs/mpmath/ext_main.pyx you messed up the spacing of """

Easy to fix.

  1. I don't understand the comment This is deprecated, but the ``TypeError`` takes precedence over the deprecation warning when this is run. How does the error "take precedence" over the warning, what are you trying to say?

By "take precedence", I mean that no deprecation warning is printed, just the TypeError. I'm trying to explain why there is no doctest with a deprecation warning. That could be clearer.

@jdemeyer
Copy link

comment:6

Replying to @jhpalmieri:

Regarding integer/rational: if I add deprecation warnings to those, I get over 800 files with failures. Many involve set_random_seed or other uses of randomization

The question is why do you get so many failures?

@jdemeyer
Copy link

comment:7

Replying to @jhpalmieri:

By "take precedence", I mean that no deprecation warning is printed, just the TypeError. I'm trying to explain why there is no doctest with a deprecation warning. That could be clearer.

I would just remove that note, it's fine.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented May 15, 2019

Branch pushed to git repo; I updated commit sha1. New commits:

2a1b5e4trac 27826: fix typo

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented May 15, 2019

Changed commit from d5fcb32 to 2a1b5e4

@jhpalmieri
Copy link
Member Author

comment:9

Replying to @jdemeyer:

Replying to @jhpalmieri:

Regarding integer/rational: if I add deprecation warnings to those, I get over 800 files with failures. Many involve set_random_seed or other uses of randomization

The question is why do you get so many failures?

I would prefer to address that on another ticket: deal with the easy cases here (and also #27829) and then think about ZZ and QQ.

I haven't investigated at all, just saw that it was a mess and so I wanted to put it off. Does Python's range try to convert to long in Python 2? Or do some other Python built-ins do that?

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented May 15, 2019

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

c70dce2trac 27826: fix typo, remove some unneeded NOTEs.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented May 15, 2019

Changed commit from 2a1b5e4 to c70dce2

@jdemeyer
Copy link

comment:11

Replying to @jhpalmieri:

I would prefer to address that on another ticket: deal with the easy cases here (and also #27829) and then think about ZZ and QQ.

-1

We clearly have no clue what we're doing or what the consequences are of that deprecation.

@jhpalmieri
Copy link
Member Author

comment:12

I have no idea what your objection is or what work you think needs doing on this ticket. Can you explain?

@jdemeyer
Copy link

comment:13

In some cases (for integers and rationals), deprecating __long__ causes a large number of warnings. We don't know why there are so many warnings. So deprecating __long__ seems to have unforeseen consequences. This is a sign that we should be prudent when deprecating __long__.

I would much prefer to deal with all cases of __long__ together (this does not necessarily mean on one ticket, but it does mean understanding the consequences of deprecating all __long__ methods).

We might also make a difference between plain Python classes and Cython cdef classes.

@jdemeyer
Copy link

comment:14

What's your plan for external packages calling long(...)? For example, fpylll does this and I don't think it's wrong for them to do that.

This is especially true from the point of view of Cython and the Python/C API, where the long class in Python 2 is the same as the int class in Python 3 (you might think that Python 3 removed the long class but what really happened is they removed int and then renamed long -> int).

So I'm now leaning towards closing this ticket as "wontfix".

@jdemeyer
Copy link

comment:15

Also numpy uses long internally (in their C code at least).

@jhpalmieri
Copy link
Member Author

comment:16

As far as I can tell, __long__ methods are not used in Python 3 (despite what you say about the renaming long -> int, int(x) does not call x.__long__()). Let me add a new goal to this, or rather make explicit a previously implicit goal: we want users to stop using the long() function, in order to ease the transition to Python 3. Deprecating __long__ is a way to do this. Is there a better way to accomplish this?

@jhpalmieri
Copy link
Member Author

comment:17

I would point out that there are many calls to long in sage.misc.randstate, so fixing those will help with some of these issues.

@jdemeyer
Copy link

comment:18

Could we replace long() in the REPL by a custom long() which shows a deprecation warning and then calls the real long()?

@embray embray modified the milestones: sage-8.9, sage-9.1 Dec 30, 2019
@mkoeppe mkoeppe modified the milestones: sage-9.1, sage-9.2 Apr 15, 2020
@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Apr 19, 2020

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

8b76372trac 27826: remove `__long__` methods, calls to long in doctests,

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Apr 19, 2020

Changed commit from ce2eb93 to 8b76372

@jhpalmieri

This comment has been minimized.

@jhpalmieri jhpalmieri changed the title Deprecate 'long(...)' Remove calls to 'long(...)', etc. Apr 19, 2020
@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Apr 19, 2020

Changed commit from 8b76372 to fc4c0fa

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Apr 19, 2020

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

fc4c0fatrac 27826: remove `__long__` methods, calls to long in doctests,

@jhpalmieri
Copy link
Member Author

comment:40

If this is merged, we can close #27696 and #27829.

@mkoeppe
Copy link
Member

mkoeppe commented Jun 14, 2020

comment:41

Needs rebasing

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 14, 2020

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

3fcba90trac 27826: remove `__long__` methods, calls to long in doctests,

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 14, 2020

Changed commit from fc4c0fa to 3fcba90

@jhpalmieri
Copy link
Member Author

comment:43

Rebased.

@mkoeppe
Copy link
Member

mkoeppe commented Jun 14, 2020

comment:44

Looks good to me but it would be good if our py3 transition experts could take a look too

@mkoeppe
Copy link
Member

mkoeppe commented Jun 18, 2020

Reviewer: Matthias Koeppe

@jhpalmieri
Copy link
Member Author

comment:46

Thank you! This one has been waiting for a while.

@vbraun
Copy link
Member

vbraun commented Jun 22, 2020

Changed branch from u/jhpalmieri/deprecate-long to 3fcba90

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants