mirror of
https://github.com/python/cpython.git
synced 2025-11-25 12:44:13 +00:00
Issue #13248: Remove inspect.getmoduleinfo() from 3.6 (deprecated in 3.3)
This commit is contained in:
parent
f1b5ccb993
commit
6dfbc5d98e
3 changed files with 5 additions and 37 deletions
|
|
@ -227,24 +227,6 @@ attributes:
|
|||
listed in the metaclass' custom :meth:`__dir__`.
|
||||
|
||||
|
||||
.. function:: getmoduleinfo(path)
|
||||
|
||||
Returns a :term:`named tuple` ``ModuleInfo(name, suffix, mode, module_type)``
|
||||
of values that describe how Python will interpret the file identified by
|
||||
*path* if it is a module, or ``None`` if it would not be identified as a
|
||||
module. In that tuple, *name* is the name of the module without the name of
|
||||
any enclosing package, *suffix* is the trailing part of the file name (which
|
||||
may not be a dot-delimited extension), *mode* is the :func:`open` mode that
|
||||
would be used (``'r'`` or ``'rb'``), and *module_type* is an integer giving
|
||||
the type of the module. *module_type* will have a value which can be
|
||||
compared to the constants defined in the :mod:`imp` module; see the
|
||||
documentation for that module for more information on module types.
|
||||
|
||||
.. deprecated:: 3.3
|
||||
You may check the file path's suffix against the supported suffixes
|
||||
listed in :mod:`importlib.machinery` to infer the same information.
|
||||
|
||||
|
||||
.. function:: getmodulename(path)
|
||||
|
||||
Return the name of the module named by the file *path*, without including the
|
||||
|
|
@ -258,8 +240,7 @@ attributes:
|
|||
still return ``None``.
|
||||
|
||||
.. versionchanged:: 3.3
|
||||
This function is now based directly on :mod:`importlib` rather than the
|
||||
deprecated :func:`getmoduleinfo`.
|
||||
The function is based directly on :mod:`importlib`.
|
||||
|
||||
|
||||
.. function:: ismodule(object)
|
||||
|
|
|
|||
|
|
@ -148,6 +148,10 @@ API and Feature Removals
|
|||
* ``inspect.getargspec()`` was removed (was deprecated since CPython 3.0).
|
||||
:func:`inspect.getfullargspec` is an almost drop in replacement.
|
||||
|
||||
* ``inspect.getmoduleinfo`` was removed (was deprecated since CPython 3.3).
|
||||
:func:`inspect.getmodulename` should be used for obtaining the module
|
||||
name for a given path.
|
||||
|
||||
|
||||
Porting to Python 3.6
|
||||
=====================
|
||||
|
|
|
|||
|
|
@ -623,23 +623,6 @@ def getfile(object):
|
|||
raise TypeError('{!r} is not a module, class, method, '
|
||||
'function, traceback, frame, or code object'.format(object))
|
||||
|
||||
ModuleInfo = namedtuple('ModuleInfo', 'name suffix mode module_type')
|
||||
|
||||
def getmoduleinfo(path):
|
||||
"""Get the module name, suffix, mode, and module type for a given file."""
|
||||
warnings.warn('inspect.getmoduleinfo() is deprecated', DeprecationWarning,
|
||||
2)
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter('ignore', PendingDeprecationWarning)
|
||||
import imp
|
||||
filename = os.path.basename(path)
|
||||
suffixes = [(-len(suffix), suffix, mode, mtype)
|
||||
for suffix, mode, mtype in imp.get_suffixes()]
|
||||
suffixes.sort() # try longest suffixes first, in case they overlap
|
||||
for neglen, suffix, mode, mtype in suffixes:
|
||||
if filename[neglen:] == suffix:
|
||||
return ModuleInfo(filename[:neglen], suffix, mode, mtype)
|
||||
|
||||
def getmodulename(path):
|
||||
"""Return the module name for a given file, or None."""
|
||||
fname = os.path.basename(path)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue