Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
py3: instead of providing a user-visible 'long' alias, just inject it…
Browse files Browse the repository at this point in the history
… into the globals for doctests, just as a transitional measure for the doctests only
  • Loading branch information
embray committed Feb 23, 2018
1 parent 45450f3 commit 036a788
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 24 deletions.
26 changes: 2 additions & 24 deletions src/sage/all.py
Expand Up @@ -15,7 +15,7 @@
sage: from sage import *
sage: frames = [x for x in gc.get_objects() if inspect.isframe(x)]
We exclude the dependencies and check to see that there are no others
We exclude the dependencies and check to see that there are no others
except for the known bad apples::
sage: allowed = [
Expand Down Expand Up @@ -68,8 +68,6 @@
import operator
import math

import six

from sage.env import SAGE_ROOT, SAGE_SRC, SAGE_DOC_SRC, SAGE_LOCAL, DOT_SAGE, SAGE_ENV


Expand Down Expand Up @@ -212,6 +210,7 @@
_cpu_time_ = cputime()
_wall_time_ = walltime()


def quit_sage(verbose=True):
"""
If you use Sage in library mode, you should call this function
Expand Down Expand Up @@ -259,27 +258,6 @@ def quit_sage(verbose=True):
symmetrica.end()


if not six.PY2:
def long(x):
"""
Deprecated replacement for the Python 2 ``long()`` built-in.
On Python 3 the ``long`` and ``int`` types have been merged into a
single ``int`` type, and there is no longer any reason to explicitly
create ``long`` objects. We add this built-in function back in for
backwards compatibility but its only effect is to return a normal
Python 2 ``int``. It is no longer a type.
"""

import sage.doctest
if not sage.doctest.DOCTEST_MODE:
from sage.misc.superseded import deprecation
deprecation(24557, 'long() is deprecated on Python 3: the normal '
'int type can hold arbitrary-precision integers')

return int(x)


sage.structure.sage_object.register_unpickle_override('sage.categories.category', 'Sets', Sets)
sage.structure.sage_object.register_unpickle_override('sage.categories.category_types', 'HeckeModules', HeckeModules)
sage.structure.sage_object.register_unpickle_override('sage.categories.category_types', 'Objects', Objects)
Expand Down
20 changes: 20 additions & 0 deletions src/sage/doctest/forker.py
Expand Up @@ -2229,6 +2229,22 @@ class DocTestTask(object):
sage: sorted(results.keys())
['cputime', 'err', 'failures', 'optionals', 'walltime']
"""

if six.PY2:
extra_globals = {}
else:
extra_globals = {'long': int}
"""
Extra objects to place in the global namespace in which tests are run.
Normally this should be empty but there are special cases where it may
be useful.
In particular, on Python 3 add ``long`` as an alias for ``int`` so that
tests that use the ``long`` built-in (of which there are many) still pass.
We do this so that the test suite can run on Python 3 while Python 2 is
still the default.
"""

def __init__(self, source):
"""
Initialization.
Expand Down Expand Up @@ -2351,6 +2367,10 @@ def _run(self, runner, options, results):
# Remove '__package__' item from the globals since it is not
# always in the globals in an actual Sage session.
dict_all.pop('__package__', None)

# Add any other special globals for testing purposes only
dict_all.update(self.extra_globals)

sage_namespace = RecordingDict(dict_all)
sage_namespace['__name__'] = '__main__'
doctests, extras = self.source.create_doctests(sage_namespace)
Expand Down

0 comments on commit 036a788

Please sign in to comment.