Skip to content

Some Invalid Relative Imports succeed in Py 3.0 & 3.1 [& correctly fail in 3.2rc1] #55135

Closed

Description

@mark-summerfield
BPO 10926
Nosy @brettcannon, @ncoghlan, @orsenthil, @mark-summerfield
Superseder
  • bpo-7902: relative import broken
  • Files
  • py-import-bug.tar.gz
  • 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 2011-01-17.17:01:49.834>
    created_at = <Date 2011-01-17.14:28:30.419>
    labels = ['interpreter-core', 'type-bug']
    title = 'Some Invalid Relative Imports succeed in Py 3.0 & 3.1 [& correctly fail in 3.2rc1]'
    updated_at = <Date 2011-01-17.17:01:49.833>
    user = 'https://github.com/mark-summerfield'

    bugs.python.org fields:

    activity = <Date 2011-01-17.17:01:49.833>
    actor = 'r.david.murray'
    assignee = 'none'
    closed = True
    closed_date = <Date 2011-01-17.17:01:49.834>
    closer = 'r.david.murray'
    components = ['Interpreter Core']
    creation = <Date 2011-01-17.14:28:30.419>
    creator = 'mark'
    dependencies = []
    files = ['20424']
    hgrepos = []
    issue_num = 10926
    keywords = []
    message_count = 3.0
    messages = ['126399', '126404', '126409']
    nosy_count = 4.0
    nosy_names = ['brett.cannon', 'ncoghlan', 'orsenthil', 'mark']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '7902'
    type = 'behavior'
    url = 'https://bugs.python.org/issue10926'
    versions = ['Python 3.1', 'Python 3.2']

    Activity

    1. mark-summerfield commented on Jan 17, 2011

      mark-summerfieldmannequin
      MannequinAuthor

      I'm reporting this at Georg Brandl's suggestion.

      If you unpack the attached (tiny) tarball you get this directory structure:

      Graphics/
      Graphics/Xpm.py
      Graphics/Vector/
      Graphics/Vector/init.py
      Graphics/Vector/Svg.py
      Graphics/init.py

      The Svg.py file has this content:

      #!/usr/bin/env python3
      from ..Graphics import Xpm
      SVG = 1

      Here are 3 interactive actions, one each for 3.0, 3.1, and 3.2rc1:

      $ python30
      Python 3.0.1 (r301:69556, Jul 15 2010, 10:31:51) 
      [GCC 4.4.4] on linux2
      Type "help", "copyright", "credits" or "license" for more information.
      >>> from Graphics.Vector import *
      >>> Svg.SVG
      1
      
      $ python31
      Python 3.1.2 (r312:79147, Jul 15 2010, 10:56:05) 
      [GCC 4.4.4] on linux2
      Type "help", "copyright", "credits" or "license" for more information.
      >>> from Graphics.Vector import *
      >>> Svg.SVG
      1
      
      $ ~/opt/python32rc1/bin/python3
      Python 3.2rc1 (r32rc1:88035, Jan 16 2011, 08:32:59) 
      [GCC 4.4.5] on linux2
      Type "help", "copyright", "credits" or "license" for more information.
      >>> from Graphics.Vector import *
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
        File "Graphics/Vector/Svg.py", line 2, in <module>
          from ..Graphics import Xpm
      ImportError: No module named Graphics

      So clearly 3.0 and 3.1 have the same behavior as each other; and this is different from 3.2rc1, and Georg says that 3.0 and 3.1 have a bug and that 3.2rc1 is correct.

      PS R. David Murray suggests that this might be related to
      http://bugs.python.org/issue7902

    2. added
      interpreter-core
      type-bug
      on Jan 17, 2011
    3. ncoghlan commented on Jan 17, 2011

      @ncoghlan
      Contributor

      Yeah, 7902 was a bug that tried to do an absolute import if an explicit relative import failed to find anything (i.e. it had inherited the old implicit relative import fallback, which was entirely inappropriate for the new use case).

      Since the significant import in these examples should correctly be written as "from .. import Xpm", it should fail in 2.6.6 and 3.1.3 as well.

      If you could confirm that at least 3.1.3 also gives the expected error message, we'll close this as a dupe of 7902.

    4. mark-summerfield commented on Jan 17, 2011

      mark-summerfieldmannequin
      MannequinAuthor

      I just installed 3.1.3 and it does indeed give the import error:

      Python 3.1.3 (r313:86834, Jan 17 2011, 16:29:46) 
      [GCC 4.4.5] on linux2
      Type "help", "copyright", "credits" or "license" for more information.
      >>> from Graphics.Vector import *
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
        File "Graphics/Vector/Svg.py", line 2, in <module>
          from ..Graphics import Xpm
      ImportError: No module named Graphics
    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

      interpreter-coretype-bug

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions