Skip to content

2to3 creates code using deprecated imp module #79751

Closed

Description

@hannob
mannequin
BPO 35570
Nosy @terryjreedy, @benjaminp, @hannob, @tirkarthi
Superseder
  • bpo-21446: Update reload fixer to use importlib instead of imp
  • 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 2018-12-29.02:54:45.442>
    created_at = <Date 2018-12-23.12:58:37.731>
    labels = ['expert-2to3']
    title = '2to3 creates code using deprecated imp module'
    updated_at = <Date 2018-12-29.02:54:45.440>
    user = 'https://github.com/hannob'

    bugs.python.org fields:

    activity = <Date 2018-12-29.02:54:45.440>
    actor = 'terry.reedy'
    assignee = 'none'
    closed = True
    closed_date = <Date 2018-12-29.02:54:45.442>
    closer = 'terry.reedy'
    components = ['2to3 (2.x to 3.x conversion tool)']
    creation = <Date 2018-12-23.12:58:37.731>
    creator = 'hanno'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 35570
    keywords = []
    message_count = 3.0
    messages = ['332390', '332395', '332692']
    nosy_count = 4.0
    nosy_names = ['terry.reedy', 'benjamin.peterson', 'hanno', 'xtreak']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '21446'
    type = None
    url = 'https://bugs.python.org/issue35570'
    versions = ['Python 3.6']

    Activity

    1. hannob commented on Dec 23, 2018

      hannobmannequin
      MannequinAuthor

      2to3 (in python 3.6.6) will rewrite the reload function to use the imp module. However according to [1] "Deprecated since version 3.4: The imp package is pending deprecation in favor of importlib."
      Also running the code with warnings enabled will show a deprecation warning.

      Example, take this minimal script:

      #!/usr/bin/python
      import sys
      reload(sys)

      Running to 2to3 ends up with:
      #!/usr/bin/python
      import sys
      import imp
      imp.reload(sys)

      $ PYTHONWARNINGS=d python3 foo.py
      test.py:3: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
        import imp

      [1] https://docs.python.org/3/library/imp.html

    2. tirkarthi commented on Dec 23, 2018

      @tirkarthi
      Member

      Seems this came up when the original version of fixer was added as noted in https://bugs.python.org/issue11797#msg206884 . Looking further this seems to be similar to https://bugs.python.org/issue21446 where it was fixed in 3.7 and master to use importlib.reload . Since 3.6 is having it's last bug fix release I am not sure of the backport. Adding benjamin.peterson to the issue .

    3. terryjreedy commented on Dec 29, 2018

      @terryjreedy
      Member

      It was decided in bpo-21446 to only backport the change, labelled an enhancement, to 3.7 and it is now too late to challenge that decision as 3.6 only gets security fixes.

    4. 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

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions