Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop using deprecated imp module; imp should now emit a real DeprecationWarning #69347

Closed
vstinner opened this issue Sep 18, 2015 · 15 comments
Closed
Labels
3.8 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@vstinner
Copy link
Member

BPO 25160
Nosy @brettcannon, @ncoghlan, @vstinner, @ambv, @ericsnowcurrently, @berkerpeksag, @JelleZijlstra, @isidentical
PRs
  • bpo-35936: Updates to modulefinder #11787
  • bpo-35936: Updates to modulefinder #11787
  • Files
  • issue25160-2to3.patch: patch for lib2to3
  • 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-06-05.18:36:26.036>
    created_at = <Date 2015-09-18.07:06:19.691>
    labels = ['3.8', 'type-feature', 'library']
    title = 'Stop using deprecated imp module; imp should now emit a real DeprecationWarning'
    updated_at = <Date 2020-06-05.18:36:26.035>
    user = 'https://github.com/vstinner'

    bugs.python.org fields:

    activity = <Date 2020-06-05.18:36:26.035>
    actor = 'brett.cannon'
    assignee = 'none'
    closed = True
    closed_date = <Date 2020-06-05.18:36:26.036>
    closer = 'brett.cannon'
    components = ['Library (Lib)']
    creation = <Date 2015-09-18.07:06:19.691>
    creator = 'vstinner'
    dependencies = []
    files = ['43113']
    hgrepos = []
    issue_num = 25160
    keywords = ['patch']
    message_count = 15.0
    messages = ['250946', '250948', '250949', '250950', '262467', '266914', '266929', '266931', '339564', '339565', '357975', '358127', '358194', '358196', '370778']
    nosy_count = 10.0
    nosy_names = ['brett.cannon', 'ncoghlan', 'vstinner', 'Arfrever', 'lukasz.langa', 'python-dev', 'eric.snow', 'berker.peksag', 'JelleZijlstra', 'BTaskaya']
    pr_nums = ['11787', '11787']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue25160'
    versions = ['Python 3.8']

    @vstinner
    Copy link
    Member Author

    The imp module is deprecated since Python 3.4. In Python 3.4, imp uses a PendingDeprecationWarning, and Python 3.5... hum, still a PendingDeprecationWarning. It was not supposed to become a real DeprecationWarning?

    Anyway, the imp module is still used in some places of the Python stdlib:

    Lib/modulefinder.py:14: import imp
    Python/makeopcodetargets.py:9:import imp
    Tools/i18n/pygettext.py:159:import imp
    Tools/importbench/importbench.py:10:import imp

    modulefinder explicitly ignore the warning :-(

    with warnings.catch_warnings():
        warnings.simplefilter('ignore', PendingDeprecationWarning)
        import imp

    @berkerpeksag
    Copy link
    Member

    Python/makeopcodetargets.py:9:import imp

    See bpo-20021.

    @berkerpeksag berkerpeksag added stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Sep 18, 2015
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Sep 18, 2015

    New changeset 03cd8340e0ce by Victor Stinner in branch '3.5':
    Issue bpo-25160: Fix import_init() comments and messages
    https://hg.python.org/cpython/rev/03cd8340e0ce

    @berkerpeksag
    Copy link
    Member

    Lib/modulefinder.py:14: import imp

    I forgot to link bpo-20020 in my earlier message :)

    @vstinner
    Copy link
    Member Author

    Tools/i18n/pygettext.py:159:import imp

    I opened the issue bpo-26639 for it.

    > Python/makeopcodetargets.py:9:import imp
    See bpo-20021.

    I pushed the change f682b620c64d but I forgot about the issue bpo-20021. Let's discuss there about this script.

    Tools/importbench/importbench.py:10:import imp

    I think that it's fine to keep imp there.

    Lib/modulefinder.py:14: import imp

    This one requires more work than the other.

    @JelleZijlstra
    Copy link
    Member

    Current status:

    I'll work on replacing some of these.

    @JelleZijlstra
    Copy link
    Member

    One more:

    • lib/pkgutil.py in _import_imp (amusingly) uses importlib with silenced warnings to import imp.

    @berkerpeksag
    Copy link
    Member

    • 2to3 replaces reload() calls with imp.reload

    There is an already open issue for this: bpo-21446.

    @ncoghlan
    Copy link
    Contributor

    ncoghlan commented Apr 7, 2019

    Fixed for Python 3.8 via the patch for bpo-35936.

    @ncoghlan ncoghlan added the 3.8 only security fixes label Apr 7, 2019
    @ncoghlan ncoghlan closed this as completed Apr 7, 2019
    @ncoghlan
    Copy link
    Contributor

    ncoghlan commented Apr 7, 2019

    Oops, this covers more than just modulefinder - reopening until the other remaining uses of the imp module have been removed.

    @ncoghlan ncoghlan reopened this Apr 7, 2019
    @isidentical
    Copy link
    Sponsor Member

    @vstinner

    Tools/importbench/importbench.py:10:import imp
    I think that it's fine to keep imp there.

    Any reason to keep imp there? We can just port it to sole importlib (it already uses it in some places)

    @brettcannon
    Copy link
    Member

    Any reason to keep imp there?

    Nope, not anymore.

    @ambv
    Copy link
    Contributor

    ambv commented Dec 10, 2019

    Make sure the standard library doesn't emit those warnings itself.

    @ambv
    Copy link
    Contributor

    ambv commented Dec 10, 2019

    I meant to comment on a different issue, the trigger is stuff like https://bugs.python.org/issue39015 (new deprecationwarnings being generated without cleaning up the standard library first).

    @brettcannon
    Copy link
    Member

    imp has been moved to DeprecationWarning and I think its usage in the stdlib has been dealt with at this point.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.8 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    7 participants