From 036a788b50a1b538c8fbd5bdb5a4ca7d07ba4a2e Mon Sep 17 00:00:00 2001 From: "Erik M. Bray" Date: Fri, 23 Feb 2018 14:33:21 +0000 Subject: [PATCH] py3: instead of providing a user-visible 'long' alias, just inject it into the globals for doctests, just as a transitional measure for the doctests only --- src/sage/all.py | 26 ++------------------------ src/sage/doctest/forker.py | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/src/sage/all.py b/src/sage/all.py index 29413aa5daa..a696d54316b 100644 --- a/src/sage/all.py +++ b/src/sage/all.py @@ -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 = [ @@ -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 @@ -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 @@ -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) diff --git a/src/sage/doctest/forker.py b/src/sage/doctest/forker.py index 4dc942c7792..91cedb604e4 100644 --- a/src/sage/doctest/forker.py +++ b/src/sage/doctest/forker.py @@ -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. @@ -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)