Commit Graph

464 Commits

Author SHA1 Message Date
Brett Cannon 5e8b04eefb Issue #21052: Don't raise ImportWarning for sys.meta_path or
sys.path_hooks when set to None during interpreter shutdown.

Thanks to Martin Panter for the initial bug report.
2014-10-10 10:54:28 -04:00
Brett Cannon 42535f0104 Fix a parameter name to make sense again 2014-05-30 16:28:00 -04:00
Brett Cannon 2a17bde930 Issue #20383: Introduce importlib.util.module_from_spec().
Along the way, dismantle importlib._bootstrap._SpecMethods as it was
no longer relevant and constructing the new function required
partially dismantling the class anyway.
2014-05-30 14:55:29 -04:00
Eric Snow b7f1be309e Merge from 3.4 (for #21226). 2014-05-12 18:25:00 -06:00
Eric Snow 08197a4616 Issue #21226: Set all attrs in PyImport_ExecCodeModuleObject. 2014-05-12 17:54:55 -06:00
Brett Cannon 6eaac13c92 Issue #21156: importlib.abc.InspectLoader.source_to_code() is now a
staticmethod.
2014-05-09 12:28:22 -04:00
Benjamin Peterson d51374ed78 PEP 465: a dedicated infix operator for matrix multiplication (closes #21176) 2014-04-09 23:55:56 -04:00
Brett Cannon a04dbe4fe7 Issue #17621: Introduce importlib.util.LazyLoader. 2014-04-04 13:53:38 -04:00
Brett Cannon a00c2407ca Issue #20884: Don't assume in importlib.__init__ that __file__ is
defined.
2014-03-21 10:58:33 -04:00
Brett Cannon 26dd0ff075 Issue #20763: Fix importlib.machinery.PathFinder to support
PathEntryFinder instances which only define find_module().

Reported by Yukihiro Nakadaira.
2014-02-26 18:26:49 -05:00
Benjamin Peterson a50fd87237 update magic number for #20625 2014-02-19 18:05:36 -05:00
Eric Snow 6029e08691 Issue 19944: Fix importlib.find_spec() so it imports parents as needed.
The function is also moved to importlib.util.
2014-01-25 15:32:46 -07:00
Eric Snow e4314e05d5 Issue 19713: Remove PEP 451-related code that should have been factored out.
This code was an artifact of issuing a DeprecationWarning for the lack
of loader.exec_module().  However, we have deferred such warnings to
later Python versions.
2014-01-07 23:29:19 -07:00
Brett Cannon 8d942296bb Issue #19719: Update various finder and loader ABCs such that their
old methods now provide implementations when PEP 451 APIs are present.

This should help with backwards-compatibility with code which has not
been updated to work with PEP 451.
2014-01-07 15:52:42 -05:00
Eric Snow 1500d49c22 Issue 19713: Add PEP 451-related deprecations. 2014-01-06 20:49:04 -07:00
Eric Snow 3192eac6cf Remove dead PEP 451 code. 2014-01-06 20:38:16 -07:00
Eric Snow d749c7ae68 Issue #19927: Add __eq__ to path-based loaders in importlib. 2014-01-04 15:06:49 -07:00
Eric Snow fbc785188d Issue #20097: Fix bad use of "self" in importlib's WindowsRegistryFinder. 2014-01-02 22:25:00 -07:00
Eric Snow 61e851baca Remove some dead code in importlib, introduced with the PEP 451 patch.
Early in the PEP 451 implementation some of the importlib loaders had
their own _get_spec() methods to simplify accommodating them.  However,
later implementations removed the need.  They simply failed to remove
this code at the same time. :)
2013-12-18 23:35:15 -07:00
Eric Snow b282b3d804 Issue #18864: Add a setter for ModuleSpec.has_location. 2013-12-10 22:16:41 -07:00
Eric Snow c1e7c747f9 Issue 19851: Fix a regression in reloading submodules. 2013-12-09 19:59:10 -07:00
Brett Cannon d2476c6e4b Issue #19698: Remove exec_module() from the built-in and extension
module loaders.

Due to the fact that the call signatures for extension modules and
built-in modules does not allow for the specifying of what module to
initialize and that on Windows all extension modules are built-in
modules, work to clean up built-in and extension module initialization
will have to wait until Python 3.5. Because of this the semantics of
exec_module() would be incorrect, so removing the methods for now is
the best option; load_module() is still used as a fallback by
importlib and so this won't affect semantics.
2013-11-29 11:00:11 -05:00
Brett Cannon 224b261258 User the repr for a module name in more places 2013-11-22 14:52:36 -05:00
Brett Cannon 175e7257b1 Remove a commented-out line 2013-11-22 12:07:43 -05:00
Brett Cannon fddc311fe8 Don't assume trying to find a builtin will succeed (e.g. posix isn't on Windows) 2013-11-22 11:58:17 -05:00
Eric Snow b523f8433a Implement PEP 451 (ModuleSpec). 2013-11-22 09:05:39 -07:00
Brett Cannon 2b8fc303ad Abstract out stat calls in importlib for easier experimentation. 2013-11-01 14:04:24 -04:00
Brett Cannon f6901c8baa Issue #19410: Put back in special-casing of '' for
importlib.machinery.FileFinder.

While originally moved to stop special-casing '' as PathFinder farther
up the typical call chain now uses the cwd in the instance of '', it
was deemed an unnecessary risk to breaking subclasses of FileFinder to
take the special-casing out.
2013-11-01 10:37:57 -04:00
Eric Snow cdf601281f Issue #19413: Restore pre-3.3 reload() semantics of re-finding modules. 2013-10-31 22:22:15 -06:00
Benjamin Peterson 6b4f7803f8 cleanup the construction of __qualname__ (closes #19301 again) 2013-10-20 17:50:28 -04:00
Benjamin Peterson 3d9e481ece give explicitly global functions and classes a global __qualname__ (closes #19301) 2013-10-19 16:01:13 -04:00
Brett Cannon 58f5680462 Issue #18810: Be optimistic with stat calls when seeing if a directory
exists when checking for a package.

Before there was an isdir check and then various isfile checks for
possible __init__ files when looking for a package.
This change drops the isdir check by leaning
on the assumption that a directory will not contain something named
after the module being imported which is not a directory. If the module
is a package then it saves a stat call. If there is nothing in the
directory with the potential package name it also saves a stat call.
Only if there is something in the directory named the same thing as
the potential package will the number of stat calls increase
(due to more wasteful __init__ checks).

Semantically there is no change as the isdir check moved
down so that namespace packages continue to have no chance of
accidentally collecting non-existent directories.
2013-10-18 13:24:13 -04:00
Brett Cannon bb9e481efa Issue #18416: Fix various os calls in importlib.machinery.FileFinder
now that self.path is no longer forced to '.'.
2013-10-18 12:01:06 -04:00
Brett Cannon 27e27f7ee1 Issue #18416: Have importlib.machinery.PathFinder treat '' as the cwd
and stop importlib.machinery.FileFinder treating '' as '.'.

Previous PathFinder transformed '' into '.' which led to __file__ for
modules imported from the cwd to always be relative paths. This meant
the values of the attribute were wrong as soon as the cwd changed.
This change now means that as long as the site module is run (which
makes all entries in sys.path absolute) then all values for __file__
will also be absolute unless it's for __main__ when specified by file
path in a relative way (modules imported by runpy will have an
absolute path).

Now that PathFinder is no longer treating '' as '.' it only makes
sense for FileFinder to stop doing so as well. Now no transformation
is performed for the directory given to the __init__ method.

Thanks to Madison May for the initial patch.
2013-10-18 11:39:04 -04:00
Eric Snow 7e70fa5314 [issue 19152] Ensure we have actually registered ExtensionFileLoader as an ExecutionLoader. 2013-10-04 20:28:52 -06:00
Eric Snow 5179445520 [issue19152] Add ExtensionFileLoader.get_filename(). 2013-10-03 12:08:55 -06:00
Eric Snow e8bbfebee0 [issue19951] Fix docstring and use of _get_suppported_file_loaders() to reflect 2-tuples. 2013-10-03 12:08:55 -06:00
Meador Inge 3c56145638 Issue #16826: Revert fix while Windows issues are being worked out. 2013-09-03 19:54:40 -05:00
Meador Inge c9e1dcdd53 Issue #16826: Revert fix while Windows issues are being worked out. 2013-09-03 19:43:49 -05:00
Meador Inge 9ab358ad7c Issue #16826: Don't check for PYTHONCASEOK when using -E.
This commit fixes a regression that sneaked into Python 3.3 where importlib
was not respecting -E when checking for the PYTHONCASEOK environment variable.
2013-09-03 16:53:22 -05:00
Meador Inge d151da9ef7 Issue #16826: Don't check for PYTHONCASEOK when using -E.
This commit fixes a regression that sneaked into Python 3.3 where importlib
was not respecting -E when checking for the PYTHONCASEOK environment variable.
2013-09-03 16:37:26 -05:00
Eric Snow 8e4554027b Closes issue #18698: ensure importlib.reload() returns the module out of sys.modules. 2013-08-14 18:11:09 -06:00
Brett Cannon e1f159722e Closes issue #18598: Have the exception message for
importlib.import_module() include the name of the module when the
'package' argument is missing but needed.
2013-08-12 13:29:11 -04:00
Ezio Melotti fbcf4d78c8 #18681: merge with 3.3. 2013-08-10 20:01:43 +03:00
Brett Cannon f0cb69274c Issue #18415: Normalize what type of quotes are used with string
constants in importlib._bootstrap. Along the way clean up from string
interpolation to use the repr explicitly.

Initial patch by Madison May.
2013-07-12 11:04:23 -04:00
Brett Cannon 7e5d55705c merge for issue #18351. 2013-07-06 18:04:41 -04:00
Brett Cannon a53cca3fea Issue #18351: Fix various issues with
importlib._bootstrap._get_sourcefile().

Thanks to its only use by the C API, it was never properly tested
until now.

Thanks to Neal Norwitz for discovering the bug and Madison May for the patch.
2013-07-06 17:56:43 -04:00
Brett Cannon 0075110ab2 Issue #18364: Stop using the ImportError._not_found hack.
The private attribute was leaking out of importlib and led to at least
one person noticing it. Switch to another hack which won't leak
outside of importlib and is nearly as robust.
2013-07-06 14:48:18 -04:00
Brett Cannon 679ecb565b Issue #15767: back out 8a0ed9f63c6e, finishing the removal of
ModuleNotFoundError.
2013-07-04 17:51:50 -04:00
Brett Cannon 82da8886cc Issue #15767: Revert 3a50025f1900 for ModuleNotFoundError 2013-07-04 17:48:16 -04:00