New submission from Martin Panter:

When no specific list of paths are given, pkgutil.iter_modules() and 
walk_packages() will list modules found on sys.path. But they don’t list 
built-in modules, which don’t live in a particular directory. So many users of 
these APIs (such as the ModuleScanner class in pydoc) have to separately 
iterate over sys.builtin_module_names.

I think it would be good to change the pkgutil module to also yield the builtin 
modules. Attached is a patch which does this.

However I had second thoughts on blindly changing the existing function to 
yield the extra modules, because this will hurt backward compatibility for 
people already working around the problem. For example, if I didn’t also update 
pydoc in my patch, a module search would list the built-in modules twice. 
Perhaps we could overcome this with an opt-in flag like 
iter_modules(builtins=True)? I’m interested if anyone else has an opinion on 
this.

Adding support for builtins could also help with proposals such as listing the 
entire library (Issue 20506) and autocompletion of module names (Issue 25419).

----------
components: Library (Lib)
files: iter-builtin.patch
keywords: patch
messages: 253905
nosy: martin.panter
priority: normal
severity: normal
status: open
title: Make pkgutil.iter_modules() yield built-in modules
type: enhancement
versions: Python 3.6
Added file: http://bugs.python.org/file40926/iter-builtin.patch

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue25533>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to