Use frozendict as type and module namespace (dictionary)

Using a frozendict as type and module namespace to “freeze them” has multiple issues. The first implementation issue is that functions of a “frozen module” keep a reference to the original mutable dictionary namespace. This issue is surprising and doesn’t look easy to solve.

The second issue is that multiple features rely on the ability to mutate a namespace to compute slow attributes. Function annotations is one example (for types), lazy imports is another (for modules). The lazy import usage can be implicit using python -X lazy_imports=all.

Last but not least, monkey-patching modules is a common practice for tests, or even for production code when using eventlet or gevent for example.

And well, overall, the trend is against this feature, people do like the ability to hack every piece of Python code for various reasons.

For all these reasons, I prefer to abandon my idea. Thanks for your valuable feedback!

People who still want frozen modules can use readonly which creates a read-only view of a module.

11 Likes