aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/importlib/util.py
Commit message (Collapse)AuthorAge
* gh-122188: Move magic number to its own file (#122243)Michael Droettboom2024-07-30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * gh-122188: Move magic number to its own file * Add versionadded directive * Do work in C * Integrate launcher.c * Make _pyc_magic_number private * Remove metadata * Move sys.implementation -> _imp * Modernize comment * Move _RAW_MAGIC_NUMBER to the C side as well * _pyc_magic_number -> pyc_magic_number * Remove unused import * Update docs * Apply suggestions from code review Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com> * Fix typo in tests --------- Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
* gh-117983: Defer import of threading for lazy module loading (#120233)Chris Markiewicz2024-07-03
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | As noted in gh-117983, the import importlib.util can be triggered at interpreter startup under some circumstances, so adding threading makes it a potentially obligatory load. Lazy loading is not used in the stdlib, so this removes an unnecessary load for the majority of users and slightly increases the cost of the first lazily loaded module. An obligatory threading load breaks gevent, which monkeypatches the stdlib. Although unsupported, there doesn't seem to be an offsetting benefit to breaking their use case. For reference, here are benchmarks for the current main branch: ``` ❯ hyperfine -w 8 './python -c "import importlib.util"' Benchmark 1: ./python -c "import importlib.util" Time (mean ± σ): 9.7 ms ± 0.7 ms [User: 7.7 ms, System: 1.8 ms] Range (min … max): 8.4 ms … 13.1 ms 313 runs ``` And with this patch: ``` ❯ hyperfine -w 8 './python -c "import importlib.util"' Benchmark 1: ./python -c "import importlib.util" Time (mean ± σ): 8.4 ms ± 0.7 ms [User: 6.8 ms, System: 1.4 ms] Range (min … max): 7.2 ms … 11.7 ms 352 runs ``` Compare to: ``` ❯ hyperfine -w 8 './python -c pass' Benchmark 1: ./python -c pass Time (mean ± σ): 7.6 ms ± 0.6 ms [User: 5.9 ms, System: 1.6 ms] Range (min … max): 6.7 ms … 11.3 ms 390 runs ``` This roughly halves the import time of importlib.util.
* gh-120417: Fix "imported but unused" linter warnings (#120461)Victor Stinner2024-06-14
| | | | | | | | | | | Add __all__ to the following modules: importlib.machinery, importlib.util and xml.sax. Add also "# noqa: F401" in collections.abc, subprocess and xml.sax. * Sort __all__; remove collections.abc.__all__; remove private names * Add tests
* gh-117182: Allow lazily loaded modules to modify their own __class__Chris Markiewicz2024-04-09
|
* gh-117178: Recover lazy loading of self-referential modules (#117179)Chris Markiewicz2024-03-28
|
* chore: fix typos (#116345)cui fliter2024-03-05
| | | Signed-off-by: cui fliter <imcusg@gmail.com>
* gh-114763: Protect lazy loading modules from attribute access races (GH-114781)Chris Markiewicz2024-02-23
| | | Setting the __class__ attribute of a lazy-loading module to ModuleType enables other threads to attempt to access attributes before the loading is complete. Now that is protected by a lock.
* Fix a misspelling of Interpeter -> Interpreter (GH-111040)Nikita Sobolev2023-10-18
|
* gh-104310: Rename the New Function in importlib.util (gh-105255)Eric Snow2023-06-08
| | | | | | | | | | | The original name wasn't as clear as it could have been. This change includes the following: * rename the function * change the default value for "disable_check" to False * add clues to the docstring that folks should probably not use the function --------- Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
* gh-104310: Add importlib.util.allowing_all_extensions() (gh-104311)Eric Snow2023-05-08
| | | (I'll be adding docs for this separately.)
* gh-82874: Convert remaining importlib format uses to f-str. (#98005)Gregory P. Smith2022-10-06
| | | f-yes
* gh-97850: Remove deprecated functions from `importlib.utils` (#97898)Nikita Sobolev2022-10-06
| | | | | * gh-97850: Remove deprecated functions from `importlib.utils` * Rebase and remove `set_package` from diff
* gh-65961: Raise `DeprecationWarning` when `__package__` differs from ↵Brett Cannon2022-10-05
| | | | | | | `__spec__.parent` (#97879) Also remove `importlib.util.set_package()` which was already slated for removal. Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
* bpo-43720: Update import-related stdlib deprecation messages to say they ↵Brett Cannon2021-04-03
| | | | will be removed in Python 3.12 (GH-25167)
* bpo-42403: Fix pyflakes warnings in importlib (GH-23396)Victor Stinner2020-11-19
| | | Remove unused imports and unused local variables.
* bpo-41006: importlib.util no longer imports typing (GH-20938)Victor Stinner2020-06-17
| | | | Create importlib._abc submodule to avoid importing typing when importlib.util is imported. Move Loader ABC into importlib._abc.
* bpo-37444: Update differing exception between builtins and importlib (GH-14869)Ngalim Siregar2019-08-02
| | | | | | | | | | Imports now raise `TypeError` instead of `ValueError` for relative import failures. This makes things consistent between `builtins.__import__` and `importlib.__import__` as well as using a more natural import for the failure. https://bugs.python.org/issue37444 Automerge-Triggered-By: @brettcannon
* bpo-30436: Add missing space in importlib.util.find_spec() error message ↵Zackery Spytz2018-06-07
| | | | (GH-7385)
* closes bpo-31650: PEP 552 (Deterministic pycs) implementation (#4575)Benjamin Peterson2017-12-09
| | | | | | | | | | | | | | | | | | | | | | | | | Python now supports checking bytecode cache up-to-dateness with a hash of the source contents rather than volatile source metadata. See the PEP for details. While a fairly straightforward idea, quite a lot of code had to be modified due to the pervasiveness of pyc implementation details in the codebase. Changes in this commit include: - The core changes to importlib to understand how to read, validate, and regenerate hash-based pycs. - Support for generating hash-based pycs in py_compile and compileall. - Modifications to our siphash implementation to support passing a custom key. We then expose it to importlib through _imp. - Updates to all places in the interpreter, standard library, and tests that manually generate or parse pyc files to grok the new format. - Support in the interpreter command line code for long options like --check-hash-based-pycs. - Tests and documentation for all of the above.
* bpo-30436: Raise ModuleNotFoundError for importlib.util.find_spec() when ↵Milan Oberkirch2017-06-14
| | | | | parent isn't a package (GH-1899) Previously AttributeError was raised, but that's not very reflective of the fact that the requested module can't be found since the specified parent isn't actually a package.
* Issue #26186: Remove the restriction that built-in and extensionBrett Cannon2016-06-25
| | | | | | | | modules can't be lazily loaded. Thanks to Python 3.6 allowing for types.ModuleType to have its __class__ mutated, the restriction can be lifted by calling create_module() on the wrapped loader.
* Merge from 3.5Brett Cannon2016-06-25
|\
| * Fix a scoping issue where an UnboundLocalError was triggered if aBrett Cannon2016-06-25
| | | | | | | | lazy-loaded module was already in sys.modules.
* | Merge for issue #26186Brett Cannon2016-02-20
|\|
| * Issue #26186: Remove an invalid type check inBrett Cannon2016-02-20
| | | | | | | | | | | | | | | | | | | | | | importlib.util.LazyLoader. The class was checking its argument as to whether its implementation of create_module() came directly from importlib.abc.Loader. The problem is that the classes coming from imoprtlib.machinery do not directly inherit from the ABC as they come from _frozen_importlib. Because the documentation has always said that create_module() was ignored, the check has simply been removed.
* | Issue #25771: Tweak ValueError message when package isn't specifiedBrett Cannon2015-12-04
|/ | | | | | for importlib.util.resolve_name() but is needed. Thanks to Martin Panter for the bug report.
* Issue #23911: Move path-based bootstrap code to a separate frozen module.Eric Snow2015-05-02
|
* Issue #19720: Suppressed context for some exceptions in importlib.Serhiy Storchaka2014-11-21
|
* Issue #20383: Introduce importlib.util.module_from_spec().Brett Cannon2014-05-30
| | | | | | Along the way, dismantle importlib._bootstrap._SpecMethods as it was no longer relevant and constructing the new function required partially dismantling the class anyway.
* Issue #17621: Introduce importlib.util.LazyLoader.Brett Cannon2014-04-04
|
* Issue 19944: Fix importlib.find_spec() so it imports parents as needed.Eric Snow2014-01-25
| | | | The function is also moved to importlib.util.
* Issue 19713: Add PEP 451-related deprecations.Eric Snow2014-01-06
|
* Implement PEP 451 (ModuleSpec).Eric Snow2013-11-22
|
* Issue #18076: Introduce imoportlib.util.decode_source().Brett Cannon2013-06-16
| | | | | | | The helper function makes it easier to implement imoprtlib.abc.InspectLoader.get_source() by making that function require just the raw bytes for source code and handling all other details.
* Issue #17907: touch up the code for imp.new_module().Brett Cannon2013-06-14
|
* Issue #18192: Introduce importlib.util.MAGIC_NUMBER and document theBrett Cannon2013-06-14
| | | | deprecation of imp.get_magic().
* fix whitespaceBrett Cannon2013-05-31
|
* Issues #18088, 18089: IntroduceBrett Cannon2013-05-31
| | | | | | | | | | | | | | | | | | | | | importlib.abc.Loader.init_module_attrs() and implement importlib.abc.InspectLoader.load_module(). The importlib.abc.Loader.init_module_attrs() method sets the various attributes on the module being loaded. It is done unconditionally to support reloading. Typically people used importlib.util.module_for_loader, but since that's a decorator there was no way to override it's actions, so init_module_attrs() came into existence to allow for overriding. This is also why module_for_loader is now pending deprecation (having its other use replaced by importlib.util.module_to_load). All of this allowed for importlib.abc.InspectLoader.load_module() to be implemented. At this point you can now implement a loader with nothing more than get_code() (which only requires get_source(); package support requires is_package()). Thanks to init_module_attrs() the implementation of load_module() is basically a context manager containing 2 methods calls, a call to exec(), and a return statement.
* Rename importlib.util.ModuleManager to module_to_load so that the nameBrett Cannon2013-05-30
| | | | explains better what the context manager is providing.
* Introduce importlib.util.ModuleManager which is a context manager toBrett Cannon2013-05-28
| | | | | | | | handle providing (and cleaning up if needed) the module to be loaded. A future commit will use the context manager in Lib/importlib/_bootstrap.py and thus why the code is placed there instead of in Lib/importlib/util.py.
* Add importlib.util.resolve_name().Brett Cannon2012-05-13
|
* PEP 3147Barry Warsaw2010-04-17
|
* Implement importlib.util.set_loader: a decorator to automatically setBrett Cannon2009-03-10
| | | | __loader__ on modules.
* Rename importlib.util.set___package__ to set_package.Brett Cannon2009-03-04
|
* Expose importlib.util.set___package__.Brett Cannon2009-03-02
|
* Implement the more specific PEP 302 semantics for loaders and what happens uponBrett Cannon2009-02-17
load failure in relation to reloads. Also expose importlib.util.module_for_loader to handle all of the details of this along with making sure all current loaders behave nicely.