Commit Graph

232 Commits

Author SHA1 Message Date
Serhiy Storchaka 41c56940c6 bpo-21720: Restore the Python 2.7 logic in handling a fromlist. (#4118)
BytesWarning no longer emitted when the fromlist argument of
__import__() or the __all__ attribute of the module contain bytes
instances.
2017-10-26 10:41:59 +03:00
Serhiy Storchaka f07e2b64df bpo-31642: Restore blocking "from" import by setting None in sys.modules. (#3834) 2017-10-08 10:44:10 +03:00
Antoine Pitrou a6a4dc816d bpo-31370: Remove support for threads-less builds (#3385)
* Remove Setup.config
* Always define WITH_THREAD for compatibility.
2017-09-07 18:56:24 +02:00
Ville Skyttä 49b2734bf1 Spelling fixes (#2902) 2017-08-03 09:00:59 +03:00
Serhiy Storchaka 8a9cd20edc bpo-30876: Relative import from unloaded package now reimports the package (#2639)
instead of failing with SystemError.

Relative import from non-package now fails with ImportError rather than
SystemError.
2017-07-12 06:50:03 +03:00
Milan Oberkirch 8c3f05e9f0 bpo-30436: Raise ModuleNotFoundError for importlib.util.find_spec() when 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.
2017-06-14 14:34:50 -07:00
Garvit Khatri 94987826e8 bpo-29851: Have importlib.reload() raise ImportError if the module's spec is not found (GH-972) 2017-05-24 15:19:50 -07:00
Serhiy Storchaka 3cc8259b71 bpo-30158: Fix deprecation warnings in test_importlib introduced by bpo-29576. (#1285) 2017-04-29 07:06:49 +03:00
Eric Appelt d6d344d833 bpo-29514: Check magic number for bugfix release (#54)
* bpo-29514: Check magic number for micro release

Add a dict importlib.util.EXPECTED_MAGIC_NUMBERS which
details the initial and expected pyc magic number for
each minor release. This gives a mechanism for users to
check if the magic number has changed within a release and
for a test to ensure procedure is followed if a change is
necessary.

Add a test to check the current MAGIC_NUMBER against the
expected number for the release if the current release is
at candidate or final level. On test failure, describe to
the developer the procedure for changing the magic number.

* Simplify magic number release test

Simplify the magic number release test by removing
EXPECTED_MAGIC_NUMBERS table and making the expected
magic number self-contained within the test.

BPO: 29514

* Improve magic number test execution and message

Improve the execution of the magic number test by
using skipUnless for alpha and beta releases, and
directly inheriting from unittest.TestCase rather than
using the machinery for the other tests. Also improve
the error message to explain the reason for caution in
changing the magic number.

BPO: 29514
2017-04-17 11:35:43 -07:00
Matthias Bussonnier 1d4601c2c6 bpo-29576: add explicit deprecation for importlib.abc.find_loader() and find_module() (GH-32) 2017-02-15 18:00:32 -08:00
Serhiy Storchaka 70d28a184c Remove unused imports. 2016-12-16 20:00:15 +02:00
Xavier de Gaye f79606debd Issue #26940: Fix test_importlib that hangs on the Android armv7 qemu emulator. 2016-12-08 11:26:18 +01:00
Eric Snow f3fd06a2e4 Issue #28026: Raise ImportError when exec_module() exists but create_module() is missing. 2016-09-08 11:12:31 -07:00
Brett Cannon 035a100382 Issue #26667: Add path-like object support to importlib.util. 2016-09-07 18:39:18 -07:00
Eric Snow 46f97b85a8 Issue #15767: Use ModuleNotFoundError. 2016-09-07 16:56:15 -07:00
Raymond Hettinger 15f44ab043 Issue #27895: Spelling fixes (Contributed by Ville Skyttä). 2016-08-30 10:47:49 -07:00
Nick Coghlan cbcd221de4 Merge #27782 fix from 3.5 2016-08-21 17:43:58 +10:00
Nick Coghlan 8682f578c1 Issue #27782: Fix m_methods handling in multiphase init
Multi-phase extension module import now correctly allows the
``m_methods`` field to be used to add module level functions
to instances of non-module types returned from ``Py_create_mod``.

Patch by Xiang Zhang.
2016-08-21 17:41:56 +10:00
Brett Cannon 4106f61c4c Merge for #27083 2016-07-16 10:45:16 -07:00
Brett Cannon 7ca63cb7cc Fix regressions introduced by fixes for issue #27083. 2016-07-16 10:44:13 -07:00
Brett Cannon b3e73b30ff Merge for #27083 2016-07-15 11:55:21 -07:00
Brett Cannon a47a7a5bf8 Issue #27083: Respect the PYTHONCASEOK environment variable under
Windows.

Originally only b'PYTHONCASEOK' was being checked for in os.environ,
but that won't work under Windows where all environment variables are
strings (on OS X they are bytes).

Thanks to Eryk Sun for the bug report.
2016-07-15 11:54:38 -07:00
Brett Cannon fdcdd9ed80 Issue #26896: Disambiguate uses of "importer" with "finder".
Thanks to Oren Milman for the patch.
2016-07-08 11:00:00 -07:00
Brett Cannon 696c35e86b Issue #26186: Remove the restriction that built-in and extension
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.
2016-06-25 10:58:17 -07:00
Brett Cannon da037616b1 Merge from 3.5 2016-06-25 10:50:24 -07:00
Brett Cannon e92dc9c23d Fix a scoping issue where an UnboundLocalError was triggered if a
lazy-loaded module was already in sys.modules.
2016-06-25 10:47:53 -07:00
Eric Snow 228ab1ff6b Issue #21099: Switch applicable importlib tests to use PEP 451 API. 2016-05-10 16:21:03 -06:00
Eric Snow d65018b17c Fixes #19711: Add tests for reloading namespace packages. 2016-05-10 15:29:05 -06:00
Serhiy Storchaka e437a10d15 Issue #23277: Remove unused imports in tests. 2016-04-24 21:41:02 +03:00
Serhiy Storchaka 597d15afe4 Issue #23277: Remove unused support.run_unittest import. 2016-04-24 13:45:58 +03:00
Serhiy Storchaka c7f44aa99a Issue #23277: Remove more unused sys and os imports. 2016-04-24 13:25:01 +03:00
Berker Peksag 1e8ee9b380 Issue #23277: Remove unused sys and os imports
Patch by Jon Dufresne.
2016-04-24 07:31:42 +03:00
Brett Cannon ef0138f421 Issue #26668: Remove the redundant Lib/test/test_importlib/regrtest.py 2016-04-08 12:29:05 -07:00
Victor Stinner 3aac0adfe0 Cleanup regrtest "main()" function
* Rename libregrtest.main_in_temp_cwd() to libregrtest.main()
* Add regrtest.main_in_temp_cwd() alias to libregrtest.main()
* Move old main_in_temp_cwd() code into libregrtest.Regrtest.main()
* Update multiple scripts to call libregrtest.main()
2016-03-24 17:53:20 +01:00
Serhiy Storchaka a051bf3afb Issue #26581: Use the first coding cookie on a line, not the last one. 2016-03-20 23:47:48 +02:00
Serhiy Storchaka e431d3c9aa Issue #26581: Use the first coding cookie on a line, not the last one. 2016-03-20 23:36:29 +02:00
Brett Cannon e5f4d3c246 Merge for issue #26186 2016-02-20 18:37:04 -08:00
Brett Cannon 558823a0cf Issue #26186: Remove an invalid type check in
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.
2016-02-20 18:35:41 -08:00
Brett Cannon 0911c0d271 Merge for issue #26367 2016-02-20 12:59:36 -08:00
Brett Cannon 4f38cb41fe Issue #26367: Have importlib.__init__() raise RuntimeError when
'level' is specified but no __package__.

This brings the function inline with builtins.__import__(). Thanks to
Manuel Jacob for the patch.
2016-02-20 12:52:06 -08:00
Serhiy Storchaka 885bdc4946 Issue #25985: sys.version_info is now used instead of sys.version
to format short Python version.
2016-02-11 13:10:36 +02:00
Brett Cannon 9fa812668f Issue #18018: Raise an ImportError if a relative import is attempted
with no known parent package.

Previously SystemError was raised if the parent package didn't exist
(e.g., __package__ was set to '').
Thanks to Florent Xicluna and Yongzhi Pan for reporting the issue.
2016-01-22 16:39:02 -08:00
Brett Cannon b0db3718d4 whitespace cleanup 2016-01-22 15:26:56 -08:00
Brett Cannon 849113af6b Issue #25791: Warn when __package__ != __spec__.parent.
In a previous change, __spec__.parent was prioritized over
__package__. That is a backwards-compatibility break, but we do
eventually want __spec__ to be the ground truth for module details. So
this change reverts the change in semantics and instead raises an
ImportWarning when __package__ != __spec__.parent to give people time
to adjust to using spec objects.
2016-01-22 15:25:50 -08:00
Brett Cannon 63b8505281 Issue #25791: Raise an ImportWarning when __spec__ or __package__ are
not defined for a relative import.

This is the start of work to try and clean up import semantics to rely
more on a module's spec than on the myriad attributes that get set on
a module. Thanks to Rose Ames for the patch.
2016-01-15 13:33:03 -08:00
Serhiy Storchaka 35abe19c24 Issue #25595: Fixed test_deleted_cwd in test_importlib on AIX. 2015-11-11 08:26:59 +02:00
Benjamin Peterson 3d1151d2c0 use assert method in another place 2015-05-30 00:02:17 -05:00
Benjamin Peterson 0a3297d7d4 use assert method (#24328) 2015-05-29 18:44:45 -05:00
Benjamin Peterson e20056c8f7 fix importing one char extension modules (closes #24328) 2015-05-29 17:10:30 -05:00
Nick Coghlan 55871f04bf Issue #24285: fix importing extensions from packages 2015-05-26 21:48:17 +10:00
Nick Coghlan d5cacbb1d9 PEP 489: Multi-phase extension module initialization
Known limitations of the current implementation:

- documentation changes are incomplete
- there's a reference leak I haven't tracked down yet

The leak is most visible by running:

  ./python -m test -R3:3 test_importlib

However, you can also see it by running:

  ./python -X showrefcount

Importing the array or _testmultiphase modules, and
then deleting them from both sys.modules and the local
namespace shows significant increases in the total
number of active references each cycle. By contrast,
with _testcapi (which continues to use single-phase
initialisation) the global refcounts stabilise after
a couple of cycles.
2015-05-23 22:24:10 +10:00
Serhiy Storchaka 041dd8eef1 Issue #15836: assertRaises(), assertRaisesRegex(), assertWarns() and
assertWarnsRegex() assertments now check the type of the first argument
to prevent possible user error.  Based on patch by Daniel Wagner-Hall.
2015-05-21 20:15:40 +03:00
Eric Snow 183a941bc1 Issue #24192: Fix namespace package imports. 2015-05-15 21:54:59 -06:00
Eric Snow 32439d6eb6 Issue #23911: Move path-based bootstrap code to a separate frozen module. 2015-05-02 19:15:18 -06:00
Brett Cannon f299abdafa Issue #23731: Implement PEP 488.
The concept of .pyo files no longer exists. Now .pyc files have an
optional `opt-` tag which specifies if any extra optimizations beyond
the peepholer were applied.
2015-04-13 14:21:02 -04:00
Brett Cannon ac9591a44a Remove a dead test for a never-launched API 2015-03-27 14:21:26 -04:00
Brett Cannon 8004e8577c Issue #22834: Drop a redundant comment and use errno instead of an
integer.

Thanks to Serhiy Storchaka and Martin Panter for the suggestions.
2015-02-27 12:13:35 -05:00
Brett Cannon 16cd19c8a2 Issue #22834: Fix a failing test under Solaris due to the platform not
allowing the deletion of the cwd.

Thanks to Martin Panter for the initial fix.
2015-02-20 09:48:18 -05:00
Brett Cannon 02d8454002 Issue #23014: Make importlib.abc.Loader.create_module() required when
importlib.abc.Loader.exec_module() is also defined.

Before this change, create_module() was optional **and** could return
None to trigger default semantics. This change now reduces the
options for choosing default semantics to one and in the most
backporting-friendly way (define create_module() to return None).
2015-01-09 11:39:21 -05:00
Steve Dower 03a144bb6a #22980 Adds platform and version tags to .pyd files 2014-12-15 20:45:23 -08:00
Zachary Ware 513112b229 Issue #22834: cwd can't not exist on Windows, skip the test 2014-11-22 17:03:46 -06:00
Brett Cannon b6e2556d8f Issue #22834: Have import suppress FileNotFoundError when the current
working directory no longer exists.

Thanks to Martin Panter for the bug report.
2014-11-21 12:19:28 -05:00
Brett Cannon 7c08b19f86 Issue #19714: Tests for importlib.machinery.WindowsRegistryFinder.
Patch by Claudiu Popa, review by Martin v. Löwis.
2014-08-22 10:28:42 -04:00
Zachary Ware f886697659 Closes #22002: Merge with 3.4 2014-07-23 12:06:47 -05:00
Zachary Ware f012ba42fe Issue #22002: Make full use of test discovery in test sub-packages.
Adds `load_package_tests` function to test.support, uses it in test_asyncio,
test_email, test_json, test_tools, test_importlib and all test_importlib
sub-packages to implement test discovery.
2014-07-23 12:00:29 -05:00
Serhiy Storchaka f2c4ba1207 Issue #19593: Use specific asserts in importlib tests. 2014-07-07 14:09:43 +03:00
Serhiy Storchaka 344f8316fd Issue #19593: Use specific asserts in importlib tests. 2014-07-07 14:08:19 +03:00
Berker Peksag f7eaa0c63c Issue #21755: Skip {Frozen,Source}_DeadlockAvoidanceTests tests when
Python is built without threads.
2014-07-03 06:25:10 +03: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
Raymond Hettinger 62f4dad816 Issue 21137: Better repr for threading.Lock() 2014-05-25 18:22:35 -07:00
Eric Snow 3497c0bf95 Issue #21503: Use test_both() consistently in test_importlib. 2014-05-16 11:40:40 -06:00
Eric Snow d50cee2045 Fix a small typo in test_importlib. 2014-05-16 11:22:05 -06:00
Eric Snow e1c9e5270a Merge from 3.4 (for #21499). 2014-05-13 12:18:07 -06:00
Eric Snow 2f46a0e8be Issue #21499: Ignore __builtins__ in several test_importlib.test_api tests. 2014-05-13 12:15:42 -06:00
Brett Cannon 732ac654c8 Issue #19721: Consolidate test_importlib utility code into a single
module.
2014-05-09 14:32:57 -04:00
Brett Cannon 91795c8e34 Issue #20776: Flesh out tests for importlib.machinery.PathFinder. 2014-05-09 13:38:11 -04:00
Brett Cannon a04dbe4fe7 Issue #17621: Introduce importlib.util.LazyLoader. 2014-04-04 13:53:38 -04:00
Eric Snow f269cc6b14 Issue #21097: Move test_namespace_pkgs into test_importlib. 2014-03-29 15:57:44 -06:00
Eric Snow c4bbd7a492 Issue #21097: Move test_namespace_pkgs into test_importlib. 2014-03-29 15:57:44 -06:00
Benjamin Peterson 85736a7d2c merge 3.3 (#20796) 2014-02-27 13:50:28 -05:00
Benjamin Peterson 3673670b67 fix importlib test failure when bytecode writing is disabled (closes #20796)
Patch by Berker Peksag.
2014-02-27 13:49:34 -05:00
Brett Cannon d3acef9bf4 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
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
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 b282b3d804 Issue #18864: Add a setter for ModuleSpec.has_location. 2013-12-10 22:16:41 -07:00
Eric Snow e3c39ddd97 Remove commented-out module spec test code and an out-of-date note. 2013-12-09 20:33:33 -07:00
Eric Snow c1e7c747f9 Issue 19851: Fix a regression in reloading submodules. 2013-12-09 19:59:10 -07:00
Eric Snow 5c29424f4b Issue #19758: silence PendingDeprecationWarnings in test_importlib. 2013-12-07 19:37:31 -07:00
Brett Cannon 2f8c83568c Issue #19712: Update test.test_importlib.source for PEP 451 2013-12-06 14:25:01 -05:00
Brett Cannon 86aae6a7b3 Issue #19712: Update test.test_importlib.import_ to test/use PEP 451
where appropriate.
2013-12-06 12:07:25 -05:00
Brett Cannon ed05b8a1a1 Issue #19712: Port test.test_importlib.import_ tests to use PEP 451
that don't require changing test.test_importlib.util.mock_modules().
2013-11-29 16:17:05 -05: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 873d1226b7 Make test_importlib output easier to trace back to the failing test
class.
2013-11-22 14:47:09 -05:00
Brett Cannon e0c3bd78c5 Issue #18864: Don't try and use unittest as a testing module for
built-in loading; leads to a reload scenario where attributes get set
which are wrong after the test.
2013-11-22 14:38:09 -05:00
Eric Snow b523f8433a Implement PEP 451 (ModuleSpec). 2013-11-22 09:05:39 -07:00
Zachary Ware 4accf45f0e Issue #19596: Set untestable tests in test_importlib to None
to avoid reporting success on empty tests.
2013-11-18 21:44:38 -06:00