[Python-ideas] re-organizing the sys module
Eric Snow
ericsnowcurrently at gmail.com
Thu Mar 13 08:43:59 CET 2014
The sys module is perhaps the most core module to Python and one of
the oldest. It has grown relatively organically over the years and
its contents could use a little clean up. Similar proposals have come
up before but without enough interest to keep them rolling.
My motivation for cleaning up sys is a combination of things:
* I'm working on a proposal that may include adding a sub-namespace to
sys (similar to what we did with sys.implementation) and removing-ish
some attributes.
* The namespace is large enough that scanning quickly through it,
particularly alphabetically a la help() or the docs, isn't very
helpful.
* Other outstanding proposals like PEP 432 may restructure underlying
APIs and having the sys module mirror the resulting APIs would help
reduce the cognitive overhead in this space.
* It would be nice to support descriptors on the module.
* The current structure does not communicate the role of the module very well.
Changing the sys module should be done carefully and as little as
possible. The status quo has something like a +10 modifier when it
comes to sys changes. The current API is pretty stable and
undoubtedly a lot of code relies on it. This proposal reflects an
understanding of those considerations and addresses them in an
entirely backward compatible way (including impact on alternate Python
implementations).
At the moment I'm not proposing any big changes to sys nor any changes
at all to its API. That can come later. <wink> Instead, this
proposal is about setting the stage for better flexibility in making
changes to sys when the need arises. Consequently I propose just
2.5000000000000001 relatively simple changes:
1. the existing sys module be renamed to _sys (and the stdlib be
changed accordingly where appropriate);
2. a pure Python sys module be added to the stdlib that wraps the existing API;
2.5. the new module should use the replace-itself-in-sys.modules
technique to provide a module subclass that supports descriptors.
Thoughts?
-eric
More information about the Python-ideas
mailing list