GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Raise ImportWarning when loader.load_module() is used · Issue #70319 · python/cpython

Raise ImportWarning when loader.load_module() is used #70319

New issue
Copy link
New issue
Copy link
Closed
Closed
Raise ImportWarning when loader.load_module() is used#70319
Copy link
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@brettcannon
brettcannon
opened on Jan 15, 2016
Issue body actions
BPO 26131
Nosy @brettcannon, @ncoghlan, @vstinner, @ericsnowcurrently, @webknjaz, @MichaelAnckaert, @brandtbucher, @nanjekyejoannah
PRs
  • bpo-26131: deprecate the use of load_module() #22905
  • gh-70319: Deprecate usage of load_module() #23469
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2020-12-07.21:27:33.787>
    created_at = <Date 2016-01-15.21:44:04.899>
    labels = ['interpreter-core', 'type-bug']
    title = 'Raise ImportWarning when loader.load_module() is used'
    updated_at = <Date 2020-12-14.13:06:12.676>
    user = 'https://github.com/brettcannon'

    bugs.python.org fields:

    activity = <Date 2020-12-14.13:06:12.676>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2020-12-07.21:27:33.787>
    closer = 'brett.cannon'
    components = ['Interpreter Core']
    creation = <Date 2016-01-15.21:44:04.899>
    creator = 'brett.cannon'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 26131
    keywords = ['patch']
    message_count = 14.0
    messages = ['258333', '347561', '347580', '349284', '349286', '349287', '349295', '379389', '382548', '382796', '382799', '382801', '382874', '382986']
    nosy_count = 8.0
    nosy_names = ['brett.cannon', 'ncoghlan', 'vstinner', 'eric.snow', 'webknjaz', 'michaelanckaert', 'brandtbucher', 'nanjekyejoannah']
    pr_nums = ['22905', '23469']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue26131'
    versions = ['Python 3.6']

    Activity

    1. brettcannon commented on Jan 15, 2016

      @brettcannon
      brettcannon
      on Jan 15, 2016
      MemberAuthor
      More actions

      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.

    2. brettcannon
      added
      interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
      type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
      on Jan 15, 2016
    3. nanjekyejoannah commented on Jul 9, 2019

      @nanjekyejoannah
      nanjekyejoannah
      on Jul 9, 2019
      Contributor
      More actions

      @brett Since this was opened like years ago. Before I work on it, I was wondering If it is still relevant.

    4. brettcannon commented on Jul 9, 2019

      @brettcannon
      brettcannon
      on Jul 9, 2019
      MemberAuthor
      More actions

      @joannah no clue if this ever happened. Could you check the code if DeprecationWarning is being raised yet?

    5. MichaelAnckaert commented on Aug 9, 2019

      @MichaelAnckaert
      MichaelAnckaertmannequin
      on Aug 9, 2019
      Mannequin
      More actions

      I checked out the source (Lib/imp.py:219) and only see the docstring marking this method als Deprecated. No exceptions are being raised.

      I would like to work on this issue.

    6. MichaelAnckaert commented on Aug 9, 2019

      @MichaelAnckaert
      MichaelAnckaertmannequin
      on Aug 9, 2019
      Mannequin
      More actions

      Clarification: the imp module shows a DeprecationWarning when imported. Was this what was meant?

    7. nanjekyejoannah commented on Aug 9, 2019

      @nanjekyejoannah
      nanjekyejoannah
      on Aug 9, 2019
      Contributor
      More actions

      Feel free to open a PR.

    8. brettcannon commented on Aug 9, 2019

      @brettcannon
      brettcannon
      on Aug 9, 2019
      MemberAuthor
      More actions

      If you look at https://github.com/python/cpython/blob/master/Lib/importlib/_bootstrap.py and https://github.com/python/cpython/blob/master/Lib/importlib/_bootstrap_external.py 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.

    9. brettcannon commented on Oct 23, 2020

      @brettcannon
      brettcannon
      on Oct 23, 2020
      MemberAuthor
      More actions

      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().

    10. brettcannon commented on Dec 4, 2020

      @brettcannon
      brettcannon
      on Dec 4, 2020
      MemberAuthor
      More actions

      New changeset 2de5097 by Brett Cannon in branch 'master':
      bpo-26131: Deprecate usage of load_module() (GH-23469)
      2de5097

    11. brettcannon
      closed this as completedon Dec 7, 2020
    12. brandtbucher commented on Dec 9, 2020

      @brandtbucher
      brandtbucher
      on Dec 9, 2020
      Member
      More actions

      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/test___all__.py", line 55, in check_all
          self.assertEqual(keys, all_set, "in module {}".format(modname))
        File "/home/bucher/src/cpython/Lib/contextlib.py", line 140, in __exit__
          next(self.gen)
        File "/home/bucher/src/cpython/Lib/test/support/warnings_helper.py", 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.

    13. brettcannon commented on Dec 9, 2020

      @brettcannon
      brettcannon
      on Dec 9, 2020
      MemberAuthor
      More actions

      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().

    14. brandtbucher commented on Dec 9, 2020

      @brandtbucher
      brandtbucher
      on Dec 9, 2020
      Member
      More actions

      Yep, looks like that was it. Thanks!

    15. webknjaz commented on Dec 11, 2020

      @webknjaz
      webknjaz
      on Dec 11, 2020
      Member
      More actions

      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: pypa/setuptools#2481.

    16. vstinner commented on Dec 14, 2020

      @vstinner
      vstinner
      on Dec 14, 2020
      Member
      More actions

      I wrote benjaminp/six#343 to fix the six module. I would appreciate a review.

    17. ezio-melotti
      transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions

        You are visitor 01402503 — GeezerVison does not store the pages you look up.
        Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.