summaryrefslogtreecommitdiff
path: root/Lib/importlib
Commit message (Collapse)AuthorAgeFilesLines
...
* bpo-45711: Remove type and traceback from exc_info (GH-30122)Irit Katriel2021-12-171-2/+3
| | | | | | | | * Do not PUSH/POP traceback or type to the stack as part of exc_info * Remove exc_traceback and exc_type from _PyErr_StackItem * Add to what's new, because this change breaks things like Cython
* bpo-44893: Implement EntryPoint as simple class with attributes. (GH-30150)Jason R. Coombs2021-12-165-66/+176
| | | | | * bpo-44893: Implement EntryPoint as simple class and deprecate tuple access in favor of attribute access. Syncs with importlib_metadata 4.8.1. * Apply refactorings found in importlib_metadata 4.8.2.
* bpo-46105: Honor spec when generating requirement specs with urls and ↵Jason R. Coombs2021-12-161-2/+11
| | | | extras. (GH-30151)
* bpo-46039: Split yield from in two (GH-30035)Mark Shannon2021-12-151-1/+2
| | | | | | * Split YIELD_FROM opcode into SEND and JUMP_ABSOLUTE. * Remove YIELD_FROM opcode.
* bpo-44525: Split calls into PRECALL and CALL (GH-30011)Mark Shannon2021-12-141-1/+2
| | | | | | | | | | * Add 3 new opcodes for calls: PRECALL_METHOD, CALL_NO_KW, CALL_KW. * Update specialization to handle new CALL opcodes. * Specialize call to method descriptors. * Remove old CALL opcodes: CALL_FUNCTION, CALL_METHOD, CALL_METHOD_KW, CALL_FUNCTION_KW.
* bpo-45292: [PEP-654] add except* (GH-29581)Irit Katriel2021-12-141-1/+2
|
* bpo-45514: Deprecate importlib resources legacy functions. (GH-29036)Jason R. Coombs2021-11-242-2/+42
| | | | | | | | | | | * bpo-45514: Apply changes from importlib_resources@a3ef4128c6 * Mark legacy functions as deprecated in the docs and link to the migration docs in importlib_resources docs. * Apply changes from importlib_resources@329ae9d5f2c. * Indicate importlib.resources as a module. Co-authored-by: Filipe Laíns <lains@riseup.net>
* bpo-45703: Invalidate _NamespacePath cache on importlib.invalidate_ca… ↵Miro Hrončok2021-11-231-1/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (GH-29384) Consider the following directory structure: . └── PATH1 └── namespace └── sub1 └── __init__.py And both PATH1 and PATH2 in sys path: $ PYTHONPATH=PATH1:PATH2 python3.11 >>> import namespace >>> import namespace.sub1 >>> namespace.__path__ _NamespacePath(['.../PATH1/namespace']) >>> ... While this interpreter still runs, PATH2/namespace/sub2 is created: . ├── PATH1 │ └── namespace │ └── sub1 │ └── __init__.py └── PATH2 └── namespace └── sub2 └── __init__.py The newly created module cannot be imported: >>> ... >>> namespace.__path__ _NamespacePath(['.../PATH1/namespace']) >>> import namespace.sub2 Traceback (most recent call last): File "<stdin>", line 1, in <module> ModuleNotFoundError: No module named 'namespace.sub2' Calling importlib.invalidate_caches() now newly allows to import it: >>> import importlib >>> importlib.invalidate_caches() >>> namespace.__path__ _NamespacePath(['.../PATH1/namespace']) >>> import namespace.sub2 >>> namespace.__path__ _NamespacePath(['.../PATH1/namespace', '.../PATH2/namespace']) This was not previously possible.
* bpo-44525: Copy free variables in bytecode to allow calls to inner functions ↵Mark Shannon2021-11-231-1/+2
| | | | | | | | | | | to be specialized (GH-29595) * Make internal APIs that take PyFrameConstructor take a PyFunctionObject instead. * Add reference to function to frame, borrow references to builtins and globals. * Add COPY_FREE_VARS instruction to allow specialization of calls to inner functions.
* bpo-45711: Re-bump the magic number and update doc (GH-29528)Brandt Bucher2021-11-121-2/+5
|
* bpo-45636: Merge all numeric operators (GH-29482)Brandt Bucher2021-11-101-0/+1
|
* bpo-45711: remove unnecessary DUP_TOP and POP in exception handling (GH-29495)Irit Katriel2021-11-101-1/+1
|
* [bpo-45765] Fix distribution discovery on empty path. (#29487)Jason R. Coombs2021-11-091-1/+1
|
* bpo-44511: Improve the bytecode for class and mapping patterns (GH-26922)Brandt Bucher2021-10-271-1/+3
| | | | | | | * Refactor mapping patterns and speed up class patterns. * Simplify MATCH_KEYS and MATCH_CLASS. * Add COPY opcode.
* bpo-35673: Add a public alias for namespace package __loader__ attribute ↵Barry Warsaw2021-10-204-6/+13
| | | | | | | | (#29049) Rename namespace package __loader__ class to be public. Make the old name, i.e. _NamespaceLoader, an alias for the public name, for backward compatibility.
* bpo-21736: Set __file__ on frozen stdlib modules. (gh-28656)Eric Snow2021-10-141-41/+136
| | | | | | | | | | | | | | | | | | | | | | | | Currently frozen modules do not have __file__ set. In their spec, origin is set to "frozen" and they are marked as not having a location. (Similarly, for frozen packages __path__ is set to an empty list.) However, for frozen stdlib modules we are able to extrapolate __file__ as long as we can determine the stdlib directory at runtime. (We now do so since gh-28586.) Having __file__ set is helpful for a number of reasons. Likewise, having a non-empty __path__ means we can import submodules of a frozen package from the filesystem (e.g. we could partially freeze the encodings module). This change sets __file__ (and adds to __path__) for frozen stdlib modules. It uses sys._stdlibdir (from gh-28586) and the frozen module alias information (from gh-28655). All that work is done in FrozenImporter (in Lib/importlib/_bootstrap.py). Also, if a frozen module is imported before importlib is bootstrapped (during interpreter initialization) then we fix up that module and its spec during the importlib bootstrapping step (i.e. imporlib._bootstrap._setup()) to match what gets set by FrozenImporter, including setting the file info (if the stdlib dir is known). To facilitate this, modules imported using PyImport_ImportFrozenModule() have __origname__ set using the frozen module alias info. __origname__ is popped off during importlib bootstrap. (To be clear, even with this change the new code to set __file__ during fixups in imporlib._bootstrap._setup() doesn't actually get triggered yet. This is because sys._stdlibdir hasn't been set yet in interpreter initialization at the point importlib is bootstrapped. However, we do fix up such modules at that point to otherwise match the result of importing through FrozenImporter, just not the __file__ and __path__ parts. Doing so will require changes in the order in which things happen during interpreter initialization. That can be addressed separately. Once it is, the file-related fixup code from this PR will kick in.) Here are things this change does not do: * set __file__ for non-stdlib modules (no way of knowing the parent dir) * set __file__ if the stdlib dir is not known (nor assume the expense of finding it) * relatedly, set __file__ if the stdlib is in a zip file * verify that the filename set to __file__ actually exists (too expensive) * update __path__ for frozen packages that alias a non-package (since there is no package dir) Other things this change skips, but we may do later: * set __file__ on modules imported using PyImport_ImportFrozenModule() * set co_filename when we unmarshal the frozen code object while importing the module (e.g. in FrozenImporter.exec_module()) -- this would allow tracebacks to show source lines * implement FrozenImporter.get_filename() and FrozenImporter.get_source() https://bugs.python.org/issue21736
* Bump MAGIC_NUMBER to reflect change in JUMP_ABSOLUTE semantics. (GH-28829)Mark Shannon2021-10-091-1/+2
|
* Fix typos in the Lib directory (GH-28775)Christian Clauss2021-10-061-3/+3
| | | | | Fix typos in the Lib directory as identified by codespell. Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
* bpo-45020: Identify which frozen modules are actually aliases. (gh-28655)Eric Snow2021-10-051-4/+29
| | | | | | | In the list of generated frozen modules at the top of Tools/scripts/freeze_modules.py, you will find that some of the modules have a different name than the module (or .py file) that is actually frozen. Let's call each case an "alias". Aliases do not come into play until we get to the (generated) list of modules in Python/frozen.c. (The tool for freezing modules, Programs/_freeze_module, is only concerned with the source file, not the module it will be used for.) Knowledge of which frozen modules are aliases (and the identity of the original module) normally isn't important. However, this information is valuable when we go to set __file__ on frozen stdlib modules. This change updates Tools/scripts/freeze_modules.py to map aliases to the original module name (or None if not a stdlib module) in Python/frozen.c. We also add a helper function in Python/import.c to look up a frozen module's alias and add the result of that function to the frozen info returned from find_frozen(). https://bugs.python.org/issue45020
* bpo-45324: Capture data in FrozenImporter.find_spec() to use in ↵Eric Snow2021-10-051-8/+24
| | | | | | | | | | | exec_module(). (gh-28633) Before this change we end up duplicating effort and throwing away data in FrozenImporter.find_spec(). Now we do the work once in find_spec() and the only thing we do in FrozenImporter.exec_module() is turn the raw frozen data into a code object and then exec it. We've added _imp.find_frozen(), add an arg to _imp.get_frozen_object(), and updated FrozenImporter. We've also moved some code around to reduce duplication, get a little more consistency in outcomes, and be more efficient. Note that this change is mostly necessary if we want to set __file__ on frozen stdlib modules. (See https://bugs.python.org/issue21736.) https://bugs.python.org/issue45324
* bpo-42135 Correct version slated for importlib.find_loader removal (GH-28312)Hugo van Kemenade2021-09-131-1/+1
| | | importlib.find_loader should also be slated for 3.12 like the others in GH-25169 and as documented in https://docs.python.org/3.11/whatsnew/3.10.html#deprecated.
* bpo-43392: Optimize repeated calls to `__import__()` (GH-24735)Germán Méndez Bravo2021-08-121-5/+16
| | | | | | | | | | | | | | | | | | | | | Implements a two steps check in `importlib._bootstrap._find_and_load()` to avoid locking when the module has been already imported and it's ready. --- Using `importlib.__import__()`, after this, does show a big difference: Before: ``` $ ./python -c 'import timeit; print(timeit.timeit("__import__(\"timeit\")", setup="from importlib import __import__"))' 15.92248619502061 ``` After: ``` $ ./python -c 'import timeit; print(timeit.timeit("__import__(\"timeit\")", setup="from importlib import __import__"))' 1.206068897008663 ``` ---
* bpo-44771: Sync with importlib_resources 5.2.2, fixing refleak. (#27497)Jason R. Coombs2021-07-301-3/+5
| | | | | * bpo-44771: Sync with importlib_resources 5.2.2, fixing refleak. * Include new 'resources' dir in the Makefile.
* bpo-44771: Apply changes from importlib_resources 5.2.1 (GH-27436)Jason R. Coombs2021-07-297-186/+345
| | | | | | | * bpo-44771: Apply changes from importlib_resources@3b24bd6307 * Add blurb * Exclude namespacedata01 from eol conversion.
* bpo-44717: improve AttributeError on circular imports of submodules (GH-27338)Filipe Laíns2021-07-241-2/+13
|
* Revert "bpo-44717: improve AttributeError on circular imports of submodules ↵Pablo Galindo Salgado2021-07-241-13/+2
| | | | | (GH-27299)" (GH-27331) This reverts commit 8072a1181dd64135f700b44372fbf7bf91e68072.
* bpo-44717: improve AttributeError on circular imports of submodules (GH-27299)Filipe Laíns2021-07-241-2/+13
| | | | | Signed-off-by: Filipe Laíns <lains@riseup.net> Co-authored-by: Łukasz Langa <lukasz@langa.pl>
* bpo-44530: Add co_qualname field to PyCodeObject (GH-26941)Gabriele N. Tornetta2021-07-071-1/+2
|
* bpo-43950: Add code.co_positions (PEP 657) (GH-26955)Pablo Galindo2021-07-021-1/+2
| | | | | | | | | | | | | | | This PR is part of PEP 657 and augments the compiler to emit ending line numbers as well as starting and ending columns from the AST into compiled code objects. This allows bytecodes to be correlated to the exact source code ranges that generated them. This information is made available through the following public APIs: * The `co_positions` method on code objects. * The C API function `PyCode_Addr2Location`. Co-authored-by: Batuhan Taskaya <isidentical@gmail.com> Co-authored-by: Ammar Askar <ammar@ammaraskar.com>
* bpo-44313: bump up magic (#26983)Batuhan Taskaya2021-07-011-1/+1
|
* bpo-44313: generate LOAD_ATTR/CALL_FUNCTION for top-level imported objects ↵Batuhan Taskaya2021-06-301-0/+1
| | | | (GH-26677)
* bpo-44464: Remove special exclusion for flake8 in the deprecation warnings. ↵Jason R. Coombs2021-06-271-9/+1
| | | | | (#26807) Sync with importlib_metadata 4.6.
* bpo-43693: Turn localspluskinds into an object (GH-26749)Guido van Rossum2021-06-211-1/+2
| | | Managing it as a bare pointer to malloc'ed bytes is just too awkward in a few places.
* bpo-38291: DeprecationWarning when importing typing.{io,re} (#26719)Sebastian Rittau2021-06-191-2/+1
|
* bpo-43693: Eliminate unused "fast locals". (gh-26587)Eric Snow2021-06-151-1/+2
| | | | | Currently, if an arg value escapes (into the closure for an inner function) we end up allocating two indices in the fast locals even though only one gets used. Additionally, using the lower index would be better in some cases, such as with no-arg `super()`. To address this, we update the compiler to fix the offsets so each variable only gets one "fast local". As a consequence, now some cell offsets are interspersed with the locals (only when an arg escapes to an inner function). https://bugs.python.org/issue43693
* Fix typos in multiple files (GH-26689)Binbin2021-06-121-1/+1
| | | Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
* bpo-43693: Un-revert commit f3fa63e. (#26609)Eric Snow2021-06-081-1/+2
| | | | | | | | | This was reverted in GH-26596 (commit 6d518bb) due to some bad memory accesses. * Add the MAKE_CELL opcode. (gh-26396) The memory accesses have been fixed. https://bugs.python.org/issue43693
* Revert "bpo-43693: Add the MAKE_CELL opcode and interleave fast locals ↵Pablo Galindo2021-06-081-2/+1
| | | | | offsets. (gh-26396)" (GH-26597) This reverts commit 631f9938b1604d4f893417ec339b9e0fa9196fb1.
* bpo-43693: Add the MAKE_CELL opcode and interleave fast locals offsets. ↵Eric Snow2021-06-071-1/+2
| | | | | | | (gh-26396) This moves logic out of the frame initialization code and into the compiler and eval loop. Doing so simplifies the runtime code and allows us to optimize it better. https://bugs.python.org/issue43693
* bpo-43693: Un-revert commits 2c1e258 and b2bf2bc. (gh-26577)Eric Snow2021-06-071-1/+3
| | | | | | | | | | These were reverted in gh-26530 (commit 17c4edc) due to refleaks. * 2c1e258 - Compute deref offsets in compiler (gh-25152) * b2bf2bc - Add new internal code objects fields: co_fastlocalnames and co_fastlocalkinds. (gh-26388) This change fixes the refleaks. https://bugs.python.org/issue43693
* bpo-43693: Revert commits 2c1e2583fdc4db6b43d163239ea42b0e8394171f and ↵Pablo Galindo2021-06-041-3/+1
| | | | | | | | | | | | | b2bf2bc1ece673d387341e06c8d3c2bc6e259747 (GH-26530) * Revert "bpo-43693: Compute deref offsets in compiler (gh-25152)" This reverts commit b2bf2bc1ece673d387341e06c8d3c2bc6e259747. * Revert "bpo-43693: Add new internal code objects fields: co_fastlocalnames and co_fastlocalkinds. (gh-26388)" This reverts commit 2c1e2583fdc4db6b43d163239ea42b0e8394171f. These two commits are breaking the refleak buildbots.
* bpo-43693: Compute deref offsets in compiler (gh-25152)Mark Shannon2021-06-031-1/+2
| | | | | | Merges locals and cells into a single array. Saves a pointer in the interpreter and means that we don't need the LOAD_CLOSURE opcode any more https://bugs.python.org/issue43693
* bpo-43693: Add new internal code objects fields: co_fastlocalnames and ↵Eric Snow2021-06-031-1/+2
| | | | | | | | | | | | | | | | | co_fastlocalkinds. (gh-26388) A number of places in the code base (notably ceval.c and frameobject.c) rely on mapping variable names to indices in the frame "locals plus" array (AKA fast locals), and thus opargs. Currently the compiler indirectly encodes that information on the code object as the tuples co_varnames, co_cellvars, and co_freevars. At runtime the dependent code must calculate the proper mapping from those, which isn't ideal and impacts performance-sensitive sections. This is something we can easily address in the compiler instead. This change addresses the situation by replacing internal use of co_varnames, etc. with a single combined tuple of names in locals-plus order, along with a minimal array mapping each to its kind (local vs. cell vs. free). These two new PyCodeObject fields, co_fastlocalnames and co_fastllocalkinds, are not exposed to Python code for now, but co_varnames, etc. are still available with the same values as before (though computed lazily). Aside from the (mild) performance impact, there are a number of other benefits: * there's now a clear, direct relationship between locals-plus and variables * code that relies on the locals-plus-to-name mapping is simpler * marshaled code objects are smaller and serialize/de-serialize faster Also note that we can take this approach further by expanding the possible values in co_fastlocalkinds to include specific argument types (e.g. positional-only, kwargs). Doing so would allow further speed-ups in _PyEval_MakeFrameVector(), which is where args get unpacked into the locals-plus array. It would also allow us to shrink marshaled code objects even further. https://bugs.python.org/issue43693
* bpo-44246: Restore compatibility in entry_points (GH-26468)Jason R. Coombs2021-05-311-1/+102
| | | | | | | * bpo-44246: Entry points performance improvements. From importlib_metadata 4.3.1. * bpo-44246: Sync with importlib_metadata 4.4
* bpo-44246: Entry points performance improvements. (GH-26467)Jason R. Coombs2021-05-311-1/+23
| | | From importlib_metadata 4.3.1.
* bpo-43693: Add _PyCode_New(). (gh-26375)Eric Snow2021-05-271-1/+2
| | | | | This is an internal-only API that helps us manage the many values used to create a code object. https://bugs.python.org/issue43693
* bpo-38693: Prefer f-strings in importlib.resources (importlib_resources ↵Jason R. Coombs2021-05-263-9/+6
| | | | | 5.0.6). (GH-26387) Automerge-Triggered-By: GH:jaraco
* bpo-38693: importlib.metadata f-strings (GH-26383)Jason R. Coombs2021-05-261-5/+4
| | | Automerge-Triggered-By: GH:jaraco
* bpo-44241: Incorporate changes from importlib_metadata 4.1. (#26382)Jason R. Coombs2021-05-263-8/+28
|
* bpo-44210: make importlib.metadata._meta.PackageMetadata public (GH-26299)Filipe Laíns2021-05-231-0/+2
| | | | | Signed-off-by: Filipe Laíns <lains@riseup.net> Automerge-Triggered-By: GH:jaraco