[Python-ideas] Add 'module' module, similar to 'keyword' module
Terry Reedy
tjreedy at udel.edu
Sat Oct 31 18:45:15 EDT 2015
On 10/31/2015 4:14 AM, Steven D'Aprano wrote:
A response to my already half-dead proposal. Literally 10 minutes after
I posted it, Guido replied that half of what I wanted already existed as
sys.builtin_module_names. I acknowledged that, two hours before
Steven's post, by saying I would go ahead and use this tuple for IDLE.
General comments: The possibility of name clashes arises because Python
does not limit import to stdlib. As Steven noted, Python cannot prevent
this. What it could do is search the all possible import sources with
each import and report clashes before picking one. I am not proposing
this. Whether python picks a user file or stdlib file when both have
the same name depends on how the stdlib version is implemented.
Specific comment: I limited the proposal to the stdlib because a) the
stdlib is fixed for a given version of CPython on a particular OS*, and
b) the reported problems of beginners that I have seen, where they are
stuck on what to do, involve the stdlib. (I could have made this
limitation clearer in my original first paragraph.) *Except as modules
are omitted in a particular build.
sys.builtin_module_names exists because the information is not otherwise
exposed and because it is needed and used in several places.
Revised and reduced proposal: If other people would find it useful, add
all_stdlib_toplevel_module_names - builtin_module_names to sys as
something equivalent to .other_stdlib_module_names or
.python_coded_module_names. Anyone wanting all_toplevel_module names
could add the two. Or add the latter, and let others subtract.
In the meanwhile, I will adapt the code in test__all__ that creates such
a list from the lib directory.
--
Terry Jan Reedy
More information about the Python-ideas
mailing list