WIP: Add __frozendict__ to type and modules - #15
Draft
vstinner wants to merge 3 commits into
Draft
Conversation
Changes: * Add _imp._module_set_frozendict() function. * importlib calls _module_set_frozendict() if a module namespace contains __frozendict__ (and is true). Modify functions to handle/support frozendict: * _PyDict_LookupIndexAndValue() * _PyModule_Clear() * module_dir() Use __frozendict__ on stdlib modules: * _abc * _ast * _operator * _stat * _struct * _thread * _types * _warnings * _weakref * _weakrefset * errno * fcntl * marshal * math * posix * select * signal * stat * textwrap * token * weakref Stdlib modules which cannot use __frozendict__: * linecache: test_linecache overrides a module attribute. * keyword: test_keyword modifies module attributes. * os: test_os overrides os atttributes. * pwd: test_getpass modifies pwd atttributes. * struct: test_struct modifies a struct attribute. * time: time.tzset() modifies attributes such as time.timezone and time.daylight. * site: test_site modify site attributes. * sys: sys.ps1 can be modified by design. * termios: test_pyrepl overrides termios attributes. * traceback: test_traceback overrides multiple traceback attributes. * _thread: test_idle overrides _thread.interrupt_main(). * warnings: warnings.showwarning() can be overriden by design. Using __frozendict__ on Mapping and MutableMapping of collections.abc doesn't work because ABCMeta.__new__() calls _abc_init(cls) which sets attributes.
Owner
Author
|
TODO: 3 tests of test_typing are still failing. |
Owner
Author
|
Reading |
vstinner
force-pushed
the
main
branch
2 times, most recently
from
July 10, 2026 17:59
e24eb61 to
fbce45b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes:
Modify functions to handle/support frozendict:
Use
__frozendict__on stdlib modules:Stdlib modules which cannot use
__frozendict__:Using
__frozendict__on Mapping and MutableMapping of collections.abc doesn't work becauseABCMeta.__new__()calls _abc_init(cls) which sets attributes.