This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Raise ImportWarning when loader.load_module() is used
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.6
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: brandtbucher, brett.cannon, eric.snow, michaelanckaert, nanjekyejoannah, ncoghlan, vstinner, webknjaz
Priority: normal Keywords: patch

Created on 2016-01-15 21:44 by brett.cannon, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 22905 closed brett.cannon, 2020-10-23 00:33
PR 23469 merged brett.cannon, 2020-11-22 20:34
Messages (14)
msg258333 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2016-01-15 21:44
Since loader.load_module() is documented as deprecated, we should consider raising an ImportWarning when it is used. That way when Python 2.7 support ends we can either remove it or have one more release where the various ImportWarnings turn into DeprecationWarnings and we finally clean up the import semantics to only be spec-based.
msg347561 - (view) Author: Joannah Nanjekye (nanjekyejoannah) * (Python committer) Date: 2019-07-09 13:29
@brett Since this was opened like years ago. Before I work on it, I was wondering If it is still relevant.
msg347580 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2019-07-09 21:43
@joannah no clue if this ever happened. Could you check the code if DeprecationWarning is being raised yet?
msg349284 - (view) Author: Michael Anckaert (michaelanckaert) * Date: 2019-08-09 13:25
I checked out the source (Lib/ and only see the docstring marking this method als Deprecated. No exceptions are being raised. 

I would like to work on this issue.
msg349286 - (view) Author: Michael Anckaert (michaelanckaert) * Date: 2019-08-09 13:29
Clarification: the imp module shows a DeprecationWarning when imported. Was this what was meant?
msg349287 - (view) Author: Joannah Nanjekye (nanjekyejoannah) * (Python committer) Date: 2019-08-09 13:30
Feel free to open a PR.
msg349295 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2019-08-09 16:50
If you look at and you will notice a bunch of comments near all the calls to load_module(). Those are the places that should be somehow triggering a DeprecationWarning.

I think there's a compatibility shim function which would need to raise an exception so that anyone who has implemented load_module() as the only way to handle loading get a warning (but I think that requires certain loaders to have appropriate support which hopefully they have already but someone needs to double-check). After that every implementation of load_module() should have a warning.
msg379389 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2020-10-23 00:38
A PR is now up. I ended up deprecating the load_module() methods in importlib itself and then raise ImportWarning in the import system itself when falling back to load_module().
msg382548 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2020-12-04 23:39
New changeset 2de5097ba4c50eba90df55696a7b2e74c93834d4 by Brett Cannon in branch 'master':
bpo-26131: Deprecate usage of load_module() (GH-23469)
msg382796 - (view) Author: Brandt Bucher (brandtbucher) * (Python committer) Date: 2020-12-09 18:29
I'm seeing the following test failure locally on master (doesn't seem to be showing up in CI though). I'm not too familiar with this stuff, but it looks related to this change:

FAIL: test_all (test.test___all__.AllTest) (module='distutils.command')
Traceback (most recent call last):
  File "/home/bucher/src/cpython/Lib/test/", line 55, in check_all
    self.assertEqual(keys, all_set, "in module {}".format(modname))
  File "/home/bucher/src/cpython/Lib/", line 140, in __exit__
  File "/home/bucher/src/cpython/Lib/test/support/", line 177, in _filterwarnings
    raise AssertionError("unhandled warning %s" % reraise[0])
AssertionError: unhandled warning {message : ImportWarning('VendorImporter.exec_module() not found; falling back to load_module()'), category : 'ImportWarning', filename : '<frozen importlib._bootstrap>', lineno : 681, line : None}


Should we be ignoring the new warning in this test as well? I'm still not sure why I seem to be the only one seeing it.
msg382799 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2020-12-09 18:40
What is "VendorImporter" (see the message of the ImportWarning)? That's not in the stdlib, so it looks like your system is injecting something via some `.pth` file or environment variable that doesn't define exec_module().
msg382801 - (view) Author: Brandt Bucher (brandtbucher) * (Python committer) Date: 2020-12-09 19:10
Yep, looks like that was it. Thanks!
msg382874 - (view) Author: Sviatoslav Sydorenko (webknjaz) * Date: 2020-12-11 17:07
> What is "VendorImporter"

@brett.cannon `VendorImporter` is something comping from `pkg_resources`. Because of an entangled traceback and the fact that it dynamically injects a vendored copy of `six`, it's hard to spot. Here's an upstream issue I filed about this warning:
msg382986 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-12-14 13:06
I wrote to fix the six module. I would appreciate a review.
Date User Action Args
2022-04-11 14:58:26adminsetgithub: 70319
2020-12-14 13:06:12vstinnersetnosy: + vstinner
messages: + msg382986
2020-12-11 17:07:17webknjazsetnosy: + webknjaz
messages: + msg382874
2020-12-09 19:10:01brandtbuchersetmessages: + msg382801
2020-12-09 18:40:10brett.cannonsetmessages: + msg382799
2020-12-09 18:29:30brandtbuchersetnosy: + brandtbucher
messages: + msg382796
2020-12-07 21:27:33brett.cannonsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2020-12-04 23:39:35brett.cannonsetmessages: + msg382548
2020-11-22 20:34:58brett.cannonsetstage: commit review -> patch review
pull_requests: + pull_request22359
2020-10-23 17:22:27brett.cannonsetstage: test needed -> commit review
2020-10-23 00:38:05brett.cannonsetmessages: + msg379389
stage: patch review -> test needed
2020-10-23 00:33:49brett.cannonsetkeywords: + patch
stage: test needed -> patch review
pull_requests: + pull_request21837
2019-08-09 16:50:43brett.cannonsetmessages: + msg349295
2019-08-09 13:30:31nanjekyejoannahsetmessages: + msg349287
2019-08-09 13:29:44michaelanckaertsetmessages: + msg349286
2019-08-09 13:25:31michaelanckaertsetnosy: + michaelanckaert
messages: + msg349284
2019-07-09 21:43:12brett.cannonsetmessages: + msg347580
2019-07-09 13:29:52nanjekyejoannahsetmessages: + msg347561
2019-07-02 14:43:35nanjekyejoannahsetnosy: + nanjekyejoannah
2016-01-15 21:44:04brett.cannoncreate