Skip to content

stdlib import mistaken for local by import_fixer #61595

Closed

Description

@regebro
mannequin
BPO 17393
Nosy @merwok, @regebro, @cedk, @romuald
PRs
  • bpo-17393: do not convert import of non-package #16826
  • Superseder
  • bpo-45544: Close 2to3 issues and list them here
  • 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 2021-10-20.23:06:48.722>
    created_at = <Date 2013-03-10.20:22:54.597>
    labels = ['type-bug', 'expert-2to3']
    title = 'stdlib import mistaken for local by import_fixer'
    updated_at = <Date 2021-10-20.23:06:48.721>
    user = 'https://github.com/regebro'

    bugs.python.org fields:

    activity = <Date 2021-10-20.23:06:48.721>
    actor = 'iritkatriel'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-10-20.23:06:48.722>
    closer = 'iritkatriel'
    components = ['2to3 (2.x to 3.x conversion tool)']
    creation = <Date 2013-03-10.20:22:54.597>
    creator = 'lregebro'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 17393
    keywords = ['patch']
    message_count = 4.0
    messages = ['183894', '183925', '183936', '354801']
    nosy_count = 4.0
    nosy_names = ['eric.araujo', 'lregebro', 'ced', 'Romuald']
    pr_nums = ['16826']
    priority = 'normal'
    resolution = 'wont fix'
    stage = 'resolved'
    status = 'closed'
    superseder = '45544'
    type = 'behavior'
    url = 'https://bugs.python.org/issue17393'
    versions = ['Python 3.3']

    Activity

    1. regebro commented on Mar 10, 2013

      regebromannequin
      MannequinAuthor

      If you have a local folder (without an init.py, hence just a normal folder) with the same name as a non local module, the import statements of that module will assumed to be local and transformed from for example import datetime to from . import datetime.

    2. merwok commented on Mar 11, 2013

      @merwok
      Member

      This is the cause for bpo-13317

    3. regebro commented on Mar 11, 2013

      regebromannequin
      MannequinAuthor

      Not really, but they are related. The fixer looks for a local module, and if it finds it it will assume the import is local.

      bpo-13317 is caused by it not finding the module, since it's not built and hence assuming it's a global import.

      This bug, contrariwise, is cause by the fixer finding a folder, and therefore assuming it is a local import when it's not.

      The fix for this is to check that the folder has an __init__.py. The fix for bpo-13317 is to build extensions before running 2to3.

      Neither of them are huge problems since you can avoid both bugs but not using relative imports. :-)

    4. romuald commented on Oct 16, 2019

      romualdmannequin
      Mannequin

      Confirming that this issue is still present on 3.8 (and working on a fix)

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

      topic-2to3type-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions