Commit Graph

110 Commits

Author SHA1 Message Date
Eric Snow bb0cf8fd60
gh-102251: Updates to test_imp Toward Fixing Some Refleaks (gh-102254)
This is related to fixing the refleaks introduced by commit 096d009.  I haven't been able to find the leak yet, but these changes are a consequence of that effort.  This includes some cleanup, some tweaks to the existing tests, and a bunch of new test cases.  The only change here that might have impact outside the tests in question is in imp.py, where I update imp.load_dynamic() to use spec_from_file_location() instead of creating a ModuleSpec directly.

Also note that I've updated the tests to only skip if we're checking for refleaks (regrtest's --huntrleaks), whereas in gh-101969 I had skipped the tests entirely.  The tests will be useful for some upcoming work and I'd rather the refleaks not hold that up.  (It isn't clear how quickly we'll be able to fix the leaking code, though it will certainly be done in the short term.)

https://github.com/python/cpython/issues/102251
2023-02-27 09:21:18 -07:00
Eric Snow 984f8ab018
gh-101758: Fix Refleak-Related Failures in test_singlephase_variants (gh-101969)
gh-101891 is causing failures under `$> ./python -m test test_imp -R 3:3`.  Furthermore, with that fixed, "test_singlephase_variants" is leaking references.  This change addresses the first part, but skips the leaking tests until we can follow up with a fix.

https://github.com/python/cpython/issues/101758
2023-02-16 17:21:22 -07:00
Eric Snow 3dea4ba6c1
gh-101758: Fix the wasm Buildbots (gh-101943)
They were broken by gh-101920.

https://github.com/python/cpython/issues/101758
2023-02-15 17:54:05 -07:00
Eric Snow b365d88465
gh-101758: Add a Test For Single-Phase Init Modules in Multiple Interpreters (gh-101920)
The test verifies the behavior of single-phase init modules when loaded in multiple interpreters.

https://github.com/python/cpython/issues/101758
2023-02-15 16:05:07 -07:00
Eric Snow b2fc549278
gh-101758: Clean Up Uses of Import State (gh-101919)
This change is almost entirely moving code around and hiding import state behind internal API.  We introduce no changes to behavior, nor to non-internal API.  (Since there was already going to be a lot of churn, I took this as an opportunity to re-organize import.c into topically-grouped sections of code.)  The motivation is to simplify a number of upcoming changes.

Specific changes:

* move existing import-related code to import.c, wherever possible
* add internal API for interacting with import state (both global and per-interpreter)
* use only API outside of import.c (to limit churn there when changing the location, etc.)
* consolidate the import-related state of PyInterpreterState into a single struct field (this changes layout slightly)
* add macros for import state in import.c (to simplify changing the location)
* group code in import.c into sections
*remove _PyState_AddModule()

https://github.com/python/cpython/issues/101758
2023-02-15 15:32:31 -07:00
Eric Snow 096d0097a0
gh-101758: Add a Test For Single-Phase Init Module Variants (gh-101891)
The new test exercises the most important variants for single-phase init extension modules. We also add some explanation about those variants to import.c.

https://github.com/python/cpython/issues/101758
2023-02-14 14:26:03 -07:00
Victor Stinner cb2ef8b2ac
gh-99578: Fix refleak in _imp.create_builtin() (#99642)
Fix a reference bug in _imp.create_builtin() after the creation of
the first sub-interpreter for modules "builtins" and "sys".
2022-11-21 12:14:54 +01:00
chgnrdv 1f369ad07f
gh-98354: Add unicode check for 'name' attribute in _imp_create_builtin (GH-98412)
Fixes #98354
2022-10-19 17:25:10 -07:00
Michael Droettboom ce1e73fbfd
gh-96272: Replace `test_source_encoding`'s `test_pep263` with `test_import_encoded_module` from `test_imp` (GH-96275)
Editors don't agree that `test_source_encoding.py` was valid koi8-r, making it
hard to edit that file without the editor breaking it in some way (see gh-96272).

Only one test actually relied on the koi8-r encoding and it was a duplicate of a
test from the deprecated `imp` module's `test_imp`, so here we replace
`test_pep263` with `test_import_encoded_module` stolen from `test_imp` and
set `test_source_encoding.py`'s encoding to utf-8 to make editing it easier
going forward.
2022-08-25 14:19:16 -05:00
Hugo van Kemenade 9b027d4cea
gh-92169: Use warnings_helper.import_deprecated() to import deprecated modules uniformly in tests (GH-92170) 2022-05-03 10:17:54 +03:00
Christian Heimes c02e860ee7
bpo-40280: Misc fixes for wasm32-emscripten (GH-30722) 2022-01-20 18:56:33 +01:00
Inada Naoki ad970e8623
bpo-29410: Change the default hash algorithm to SipHash13. (GH-28752)
Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@innova.no>
Co-authored-by: Christian Heimes <christian@python.org>
2021-10-10 17:29:46 +09:00
Eric Snow cbeb819710
bpo-45020: Freeze some of the modules imported during startup. (gh-28335)
Doing this provides significant performance gains for runtime startup (~15% with all the imported modules frozen). We don't yet freeze all the imported modules because there are a few hiccups in the build systems we need to sort out first. (See bpo-45186 and bpo-45188.)

Note that in PR GH-28320 we added a command-line flag (-X frozen_modules=[on|off]) that allows users to opt out of (or into) using frozen modules. The default is still "off" but we will change it to "on" as soon as we can do it in a way that does not cause contributors pain.

https://bugs.python.org/issue45020
2021-09-15 10:19:30 -06:00
Inada Naoki c8e5eb904e
bpo-43651: PEP 597: Fix EncodingWarning in some tests (GH-25181)
* Fix test_shutil
* Fix test_imp
* Fix test_import
* Fix test_importlib
2021-04-05 13:11:23 +09:00
Hai Shi f7ba40b505
bpo-40275: Use new test.support helper submodules in tests (GH-20849) 2020-06-25 12:38:51 +02:00
Nina Zakharenko 69091cb497 bpo-35321: Set the spec origin to frozen in frozen modules (#11732)
* bpo-35321: Set the spec origin to frozen in frozen modules

This fix correctly sets the spec origin to
"frozen" for the _frozen_importlib module. Note that the
origin was already correctly set in _frozen_importlib_external.

* 📜🤖 Added by blurb_it.
2019-02-04 16:56:26 -08:00
Benjamin Peterson b0274f2cdd
closes bpo-34056: Always return bytes from _HackedGetData.get_data(). (GH-8130)
* Always return bytes from _HackedGetData.get_data().

Ensure the imp.load_source shim always returns bytes by reopening the file in
binary mode if needed. Hash-based pycs have to receive the source code in bytes.

It's tempting to change imp.get_suffixes() to always return 'rb' as a mode, but
that breaks some stdlib tests and likely 3rdparty code, too.
2018-07-06 20:41:06 -07:00
Benjamin Peterson 42aa93b8ff
closes bpo-31650: PEP 552 (Deterministic pycs) implementation (#4575)
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.
2017-12-09 10:26:52 -08:00
luzpaz a5293b4ff2 Fix miscellaneous typos (#4275) 2017-11-05 15:37:50 +02:00
Victor Stinner a505ecdc50 bpo-31676: Fix test_imp.test_load_source() side effect (#3871)
test_load_source() now replaces the current __name__ module with a
temporary module to prevent side effects.
2017-10-13 13:47:49 -07:00
Oren Milman 9974e1bcf3 bpo-31315: Fix an assertion failure in imp.create_dynamic(), when spec.name is not a string. (#3257) 2017-09-19 14:39:47 +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
Serhiy Storchaka f7eae0adfc [security] bpo-13617: Reject embedded null characters in wchar* strings. (#2302)
Based on patch by Victor Stinner.

Add private C API function _PyUnicode_AsUnicode() which is similar to
PyUnicode_AsUnicode(), but checks for null characters.
2017-06-28 08:30:06 +03:00
Serhiy Storchaka a6f26c1d34 Remove more unused imports in tests. 2016-04-25 00:05:30 +03:00
Brett Cannon 213b4056a6 Issue #25487: Fix tests not updated when the imp module moved to a
DeprecationWarning.

Thanks to Martin Panter for finding the tests.
2015-10-30 14:41:06 -07:00
Nick Coghlan 9d3c61c86a Close #24748: Restore imp.load_dynamic compatibility
To resolve a compatibility problem found with py2exe and
pywin32, imp.load_dynamic() once again ignores previously loaded modules
to support Python modules replacing themselves with extension modules.

Patch by Petr Viktorin.
2015-09-05 21:05:05 +10: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
Victor Stinner 047b7ae566 Issue #22390: Remove files created by tests 2014-10-05 17:37:41 +02:00
Zachary Ware 101d9e7250 Issue 19572: More silently skipped tests explicitly skipped. 2013-12-08 00:44:27 -06:00
Zachary Ware 9fe6d86709 Issue 19572: More silently skipped tests explicitly skipped. 2013-12-08 00:20:35 -06:00
Serhiy Storchaka 6787a3806e Issue #15204: Deprecated the 'U' mode in file-like objects. 2013-11-23 22:12:06 +02:00
Brett Cannon 330cc52c99 Delete merge markers 2013-08-23 12:10:09 -04:00
Brett Cannon 16ababc213 merge for issue #18755 2013-08-23 11:52:19 -04:00
Brett Cannon a4975a911d Issue #18755: Allow imp.load_*() loaders to have get_data() called
multiple times.
2013-08-23 11:45:57 -04:00
Antoine Pitrou bb2c45e7a4 Issue #7732: try to fix test_bug7732's flakiness on Windows by executing it in a fresh temporary directory. 2013-08-19 23:31:18 +02:00
Eric Snow 7491f1726b issue #18698: ensure importlib.reload() returns the module out of sys.modules. 2013-08-14 18:03:34 -06:00
Serhiy Storchaka 3ee11407f8 Issue #18706: Fix a test for issue #18681 so it no longer breaks test_codeccallbacks*. 2013-08-11 20:13:36 +03:00
Serhiy Storchaka b212291b08 Issue #18706: Fix a test for issue #18681 so it no longer breaks test_codeccallbacks*. 2013-08-11 20:12:20 +03:00
Ezio Melotti fbcf4d78c8 #18681: merge with 3.3. 2013-08-10 20:01:43 +03:00
Ezio Melotti 056bafe7a6 #18681: Fix a NameError in imp.reload() (noticed by Weizhao Li). 2013-08-10 19:59:36 +03:00
Brett Cannon e4f41deccf Issue #17177: The imp module is pending deprecation.
To make sure there is no issue with code that is both Python 2 and 3
compatible, there are no plans to remove the module any sooner than
Python 4 (unless the community moves to Python 3 solidly before then).
2013-06-16 13:13:40 -04:00
Brett Cannon 997487d5d7 Issue #7732: Move an imp.find_module test from test_import to
test_imp.
2013-06-07 13:26:53 -04:00
Benjamin Peterson fc6f4cd398 merge 3.3 2013-05-11 16:29:11 -05:00
Benjamin Peterson aa6f688bd4 only close non-None files 2013-05-11 16:29:03 -05:00
Brett Cannon dea2ec4b1d Fix a test to not use an assertion for something that could be
legitimately false.
2013-05-04 18:11:12 -04:00
Brett Cannon 8772b18bc4 Change a test assertion to a conditional so the test will pass on
Windows.
2013-05-04 17:54:57 -04:00
Brett Cannon 95ea11fa31 add trailing newline to file 2013-05-03 10:57:08 -04:00
Brett Cannon 142685337f Move test_imp over to unittest.main() 2013-05-03 10:56:19 -04:00
Brett Cannon 130e48199a Guard more tests in test_imp requiring imp.load_dynamic() to exist. 2013-05-03 10:54:23 -04:00
Brett Cannon 2a9c653f38 #15902: merge w/ 3.3 2013-05-03 10:47:17 -04:00