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

2to3 does relative import for modules not in a package. #48251

Closed
mhammond opened this issue Sep 30, 2008 · 4 comments
Closed

2to3 does relative import for modules not in a package. #48251

mhammond opened this issue Sep 30, 2008 · 4 comments

Comments

@mhammond
Copy link
Contributor

BPO 4001
Nosy @mhammond, @benjaminp
Files
  • relative_must_be_package.patch: check module is in a package before assuming a relative import.
  • 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 2008-09-30.23:27:23.524>
    created_at = <Date 2008-09-30.13:20:30.990>
    labels = ['expert-2to3']
    title = '2to3 does relative import for modules not in a package.'
    updated_at = <Date 2008-10-04.00:40:17.401>
    user = 'https://github.com/mhammond'

    bugs.python.org fields:

    activity = <Date 2008-10-04.00:40:17.401>
    actor = 'benjamin.peterson'
    assignee = 'none'
    closed = True
    closed_date = <Date 2008-09-30.23:27:23.524>
    closer = 'benjamin.peterson'
    components = ['2to3 (2.x to 3.x conversion tool)']
    creation = <Date 2008-09-30.13:20:30.990>
    creator = 'mhammond'
    dependencies = []
    files = ['11662']
    hgrepos = []
    issue_num = 4001
    keywords = ['patch']
    message_count = 4.0
    messages = ['74075', '74103', '74289', '74290']
    nosy_count = 2.0
    nosy_names = ['mhammond', 'benjamin.peterson']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue4001'
    versions = []

    @mhammond
    Copy link
    Contributor Author

    Create an empty directory with only 2 files, foo.py and bar.py, both
    exactly 1 line:

    foo.py:
    |from bar import bar
    bar.py:
    |bar = "bar"

    Running 2to3 results in the following patch for foo.py:
    -from bar import bar
    +from .bar import bar

    However, the resulting foo.py fails to run - the 2 files are not in a
    package, so we get:

    | ValueError: Attempted relative import in non-package

    Attaching a patch which checks there is an __init__.py in the same
    directory as the files before it considers it a potential relative import.

    @benjaminp
    Copy link
    Contributor

    Thanks. Fixed in r66707.

    @mhammond
    Copy link
    Contributor Author

    mhammond commented Oct 4, 2008

    I must be going crazy, but I can't see r66707 in the trunk, the py3k
    branch, or anywhere else in the svn tree. Can you please lend me a
    clue-stick?

    @benjaminp
    Copy link
    Contributor

    On Fri, Oct 3, 2008 at 7:39 PM, Mark Hammond <report@bugs.python.org> wrote:

    Mark Hammond <mhammond@users.sourceforge.net> added the comment:

    I must be going crazy, but I can't see r66707 in the trunk, the py3k
    branch, or anywhere else in the svn tree. Can you please lend me a
    clue-stick?

    You're not crazy; it's just hidden. :)

    It's in the 2to3 main line of development: /sandbox/trunk/2to3

    I'll merge into the trunk and py3k soon.

    @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
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants