summaryrefslogtreecommitdiffstats
path: root/Lib/imp.py
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2012-05-11 16:58:42 (GMT)
committerBrett Cannon <brett@python.org>2012-05-11 16:58:42 (GMT)
commitcb66eb0deca1d5cd232f97c76a215ecaab958d30 (patch)
treef38497a2e61cf8be225c4e7394961703cea5f66c /Lib/imp.py
parent810c64df8f8bf70a2cb7a626004185616cb88213 (diff)
downloadcpython-cb66eb0deca1d5cd232f97c76a215ecaab958d30.zip
cpython-cb66eb0deca1d5cd232f97c76a215ecaab958d30.tar.gz
cpython-cb66eb0deca1d5cd232f97c76a215ecaab958d30.tar.bz2
Issue #13959: Deprecate imp.get_suffixes() for new attributes on
importlib.machinery that provide the suffix details for import. The attributes were not put on imp so as to compartmentalize everything importlib needs for setting up imports in importlib.machinery. This also led to an indirect deprecation of inspect.getmoduleinfo() as it directly returned imp.get_suffix's returned tuple which no longer makes sense.
Diffstat (limited to 'Lib/imp.py')
-rw-r--r--Lib/imp.py33
1 files changed, 20 insertions, 13 deletions
diff --git a/Lib/imp.py b/Lib/imp.py
index 717b6a4..f60f050 100644
--- a/Lib/imp.py
+++ b/Lib/imp.py
@@ -17,9 +17,11 @@ from importlib._bootstrap import new_module
from importlib._bootstrap import cache_from_source
from importlib import _bootstrap
+from importlib import machinery
import os
import sys
import tokenize
+import warnings
# XXX "deprecate" once find_module(), load_module(), and get_suffixes() are
@@ -37,9 +39,12 @@ IMP_HOOK = 9
def get_suffixes():
+ warnings.warn('imp.get_suffixes() is deprecated; use the constants '
+ 'defined on importlib.machinery instead',
+ DeprecationWarning, 2)
extensions = [(s, 'rb', C_EXTENSION) for s in extension_suffixes()]
- source = [(s, 'U', PY_SOURCE) for s in _bootstrap._SOURCE_SUFFIXES]
- bytecode = [(_bootstrap._BYTECODE_SUFFIX, 'rb', PY_COMPILED)]
+ source = [(s, 'U', PY_SOURCE) for s in machinery.SOURCE_SUFFIXES]
+ bytecode = [(s, 'rb', PY_COMPILED) for s in machinery.BYTECODE_SUFFIXES]
return extensions + source + bytecode
@@ -61,7 +66,7 @@ def source_from_cache(path):
raise ValueError('expected only 2 dots in '
'{!r}'.format(pycache_filename))
base_filename = pycache_filename.partition('.')[0]
- return os.path.join(head, base_filename + _bootstrap._SOURCE_SUFFIXES[0])
+ return os.path.join(head, base_filename + machinery.SOURCE_SUFFIXES[0])
class NullImporter:
@@ -126,7 +131,7 @@ def load_compiled(name, pathname, file=None):
# XXX deprecate
def load_package(name, path):
if os.path.isdir(path):
- extensions = _bootstrap._SOURCE_SUFFIXES + [_bootstrap._BYTECODE_SUFFIX]
+ extensions = machinery.SOURCE_SUFFIXES[:] + [machinery.BYTECODE_SUFFIXES]
for extension in extensions:
path = os.path.join(path, '__init__'+extension)
if os.path.exists(path):
@@ -190,19 +195,21 @@ def find_module(name, path=None):
for entry in path:
package_directory = os.path.join(entry, name)
- for suffix in ['.py', _bootstrap._BYTECODE_SUFFIX]:
+ for suffix in ['.py', machinery.BYTECODE_SUFFIXES[0]]:
package_file_name = '__init__' + suffix
file_path = os.path.join(package_directory, package_file_name)
if os.path.isfile(file_path):
return None, package_directory, ('', '', PKG_DIRECTORY)
- for suffix, mode, type_ in get_suffixes():
- file_name = name + suffix
- file_path = os.path.join(entry, file_name)
- if os.path.isfile(file_path):
- break
- else:
- continue
- break # Break out of outer loop when breaking out of inner loop.
+ with warnings.catch_warnings():
+ warnings.simplefilter('ignore')
+ for suffix, mode, type_ in get_suffixes():
+ file_name = name + suffix
+ file_path = os.path.join(entry, file_name)
+ if os.path.isfile(file_path):
+ break
+ else:
+ continue
+ break # Break out of outer loop when breaking out of inner loop.
else:
raise ImportError('No module name {!r}'.format(name), name=name)