On Fri, Aug 25, 2017 at 8:18 AM, Yury Selivanov <yselivanov...@gmail.com> wrote: > Another idea: > > 1. We alter PyModule to make it possible to add properties (descriptor > protocol, or we implement custom __getattr__). I think we can make it > so that only sys module would be able to actually use it, so it's not > going to be a new feature -- just a hack for CPython.
FWIW, I've been toying with a similar problem and solution for a while. I'd like to clean up the sys module, including grouping some of the attributes (e.g. the import state), turn the get/set pairs into properties, and deprecate direct usage of some of the attributes. Though supporting descriptors on module objects would work [1] and be useful (particularly deprecating module attrs), it's sufficiently worthy of a PEP that I haven't taken the time. Instead, the approach I settled on was to rename sys to _sys and add a sys written in Python that proxies _sys. Here's a rough first pass: https://github.com/ericsnowcurrently/cpython/tree/sys-module It's effectively the same thing as ModuleType supporting descriptors, but specific only to sys. One problem with both approaches is that we'd be changing the type of the sys module. There's a relatively common idiom in the stdlib (and elsewhere) of using "type(sys)" to get ModuleType. Changing the type of the sys module breaks that. -eric [1] This is doable with a custom __getattribute__ on ModuleType, though it will impact attribute lookup on all modules. I suppose there could be a subclass that does the right thing... Anyway, this is more python-ideas territory. _______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com