classification
Title: pkgutil.walk_packages is using a deprecated API
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: brett.cannon, georg.brandl, ncoghlan, python-dev
Priority: normal Keywords:

Created on 2012-07-18 11:56 by ncoghlan, last changed 2012-07-18 13:49 by brett.cannon. This issue is now closed.

Messages (5)
msg165759 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2012-07-18 11:56
$ ./python -Wdefault
Python 3.3.0b1 (default:8bf691d0b004+, Jul 15 2012, 23:20:06) 
[GCC 4.7.0 20120507 (Red Hat 4.7.0-5)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pkgutil
>>> list(pkgutil.walk_packages("."))
/home/ncoghlan/devel/py3k/Lib/inspect.py:453: DeprecationWarning: inspect.getmoduleinfo() is deprecated
  info = getmoduleinfo(path)
/home/ncoghlan/devel/py3k/Lib/inspect.py:445: DeprecationWarning: imp.get_suffixes() is deprecated; use the constants defined on importlib.machinery instead
  for suffix, mode, mtype in imp.get_suffixes()]
[(FileFinder('.'), 'foo', False), (FileFinder('.'), 'python-gdb', False), (FileFinder('.'), 'setup', False)]

The problem is the calls to inspect.getmodulename().

Do these APIs really need to be deprecated? Can't they just be redirected to importlib instead?
msg165766 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2012-07-18 12:59
I think the imp functions do need to go away. They perpetuate an absolutely horrendous API that I'm trying to slowly kill (and the underlying imp code is already reusing importlib). They already are a burden for future API growth as people already rely on imp.find_module() and imp.load_module() in such a way that untangling is right pain.
msg165769 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-07-18 13:15
New changeset af7961e1c362 by Nick Coghlan in branch 'default':
Close #15387: inspect.getmodulename() now uses a new importlib.machinery.all_suffixes() API rather than the deprecated inspect.getmoduleinfo()
http://hg.python.org/cpython/rev/af7961e1c362
msg165770 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2012-07-18 13:20
The problem turned out to just be inspect.getmodulename() still relying on the deprecated inspect.getmoduleinfo(), so I changed it to be based on importlib.machinery instead.

I did make an importlib API addition to do it though - the all_suffixes() function dynamically adds together all the suffixes relevant for the current process so it will pick up any modification post import, while still allowing code that doesn't care about module types to ignore the details of the different kinds.
msg165775 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2012-07-18 13:49
RE: the API addition: fine by me if it makes your life easier.
History
Date User Action Args
2012-07-18 13:49:23brett.cannonsetmessages: + msg165775
2012-07-18 13:20:39ncoghlansetmessages: + msg165770
2012-07-18 13:15:11python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg165769

resolution: fixed
stage: needs patch -> resolved
2012-07-18 12:59:45brett.cannonsetmessages: + msg165766
2012-07-18 11:56:13ncoghlancreate