Skip to content

Commit 0270a4b

Browse files
committed
Speed up importing of past.translation (issue #117)
Also: give more descriptive error messages if top-level packages are imported somehow on Py3.
1 parent 67971ec commit 0270a4b

File tree

23 files changed

+124
-93
lines changed

23 files changed

+124
-93
lines changed

src/_dummy_thread/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@
55
if sys.version_info[0] < 3:
66
from dummy_thread import *
77
else:
8-
raise ImportError('Cannot import module from python-future source folder')
8+
raise ImportError('This package should not be accessible on Python 3. '
9+
'Either you are trying to run from the python-future src folder '
10+
'or your installation of python-future is corrupted.')

src/_markupbase/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@
55
if sys.version_info[0] < 3:
66
from markupbase import *
77
else:
8-
raise ImportError('Cannot import module from python-future source folder')
8+
raise ImportError('This package should not be accessible on Python 3. '
9+
'Either you are trying to run from the python-future src folder '
10+
'or your installation of python-future is corrupted.')

src/_thread/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@
55
if sys.version_info[0] < 3:
66
from dummy_thread import *
77
else:
8-
raise ImportError('Cannot import module from python-future source folder')
8+
raise ImportError('This package should not be accessible on Python 3. '
9+
'Either you are trying to run from the python-future src folder '
10+
'or your installation of python-future is corrupted.')

src/builtins/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@
77
# Overwrite any old definitions with the equivalent future.builtins ones:
88
from future.builtins import *
99
else:
10-
raise ImportError('Cannot import module from python-future source folder')
10+
raise ImportError('This package should not be accessible on Python 3. '
11+
'Either you are trying to run from the python-future src folder '
12+
'or your installation of python-future is corrupted.')

src/configparser/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,11 @@
33

44
if sys.version_info[0] < 3:
55
from ConfigParser import *
6+
try:
7+
from ConfigParser import (_Chainmap, Error, InterpolationMissingOptionError)
8+
except ImportError:
9+
pass
610
else:
7-
raise ImportError('Cannot import module from python-future source folder')
11+
raise ImportError('This package should not be accessible on Python 3. '
12+
'Either you are trying to run from the python-future src folder '
13+
'or your installation of python-future is corrupted.')

src/copyreg/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from __future__ import absolute_import
2-
from future.utils import PY3
2+
import sys
33

4-
if PY3:
5-
raise ImportError('Cannot import module from python-future source folder')
6-
from copyreg import *
7-
else:
8-
__future_module__ = True
4+
if sys.version_info[0] < 3:
95
from copy_reg import *
6+
else:
7+
raise ImportError('This package should not be accessible on Python 3. '
8+
'Either you are trying to run from the python-future src folder '
9+
'or your installation of python-future is corrupted.')

src/future/standard_library/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ def load_module(self, name):
267267
# New name. Look up the corresponding old (Py2) name:
268268
oldname = self.new_to_old[name]
269269
module = self._find_and_load_module(oldname)
270-
module.__future_module__ = True
270+
# module.__future_module__ = True
271271
else:
272272
module = self._find_and_load_module(name)
273273
# In any case, make it available under the requested (Py3) name
@@ -451,7 +451,7 @@ def install_aliases():
451451
# We look up the module in sys.modules because __import__ just returns the
452452
# top-level package:
453453
newmod = sys.modules[newmodname]
454-
newmod.__future_module__ = True
454+
# newmod.__future_module__ = True
455455

456456
__import__(oldmodname)
457457
oldmod = sys.modules[oldmodname]

src/html/__init__.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from __future__ import absolute_import
22
import sys
3-
__future_module__ = True
43

5-
if sys.version_info[0] == 3:
6-
raise ImportError('Cannot import module from python-future source folder')
7-
else:
4+
if sys.version_info[0] < 3:
85
from future.moves.html import *
6+
else:
7+
raise ImportError('This package should not be accessible on Python 3. '
8+
'Either you are trying to run from the python-future src folder '
9+
'or your installation of python-future is corrupted.')

src/http/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from __future__ import absolute_import
22
import sys
3-
__future_module__ = True
43

54
if sys.version_info[0] < 3:
65
pass
76
else:
8-
raise ImportError('Cannot import module from python-future source folder')
7+
raise ImportError('This package should not be accessible on Python 3. '
8+
'Either you are trying to run from the python-future src folder '
9+
'or your installation of python-future is corrupted.')

src/http/client.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
from __future__ import absolute_import
22
import sys
3-
__future_module__ = True
43

5-
if sys.version_info[0] < 3:
6-
from httplib import *
7-
else:
8-
raise ImportError('Cannot import module from python-future source folder')
4+
assert sys.version_info[0] < 3
5+
6+
from httplib import *

0 commit comments

Comments
 (0)