GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — IMPORT PROBLEM: Local submodule shadows global module · Issue #42852 · python/cpython

IMPORT PROBLEM: Local submodule shadows global module #42852

New issue
Copy link
New issue
Copy link
Closed
Closed
IMPORT PROBLEM: Local submodule shadows global module#42852
Copy link
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)

Description

jensengel
mannequin
opened on Feb 1, 2006
Issue body actions
BPO 1421513
Nosy @birkenfeld

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 2006-02-17.12:13:09.000>
created_at = <Date 2006-02-01.14:48:37.000>
labels = ['interpreter-core']
title = 'IMPORT PROBLEM: Local submodule shadows global module'
updated_at = <Date 2006-02-17.12:13:09.000>
user = 'https://bugs.python.org/jensengel'

bugs.python.org fields:

activity = <Date 2006-02-17.12:13:09.000>
actor = 'georg.brandl'
assignee = 'none'
closed = True
closed_date = None
closer = None
components = ['Interpreter Core']
creation = <Date 2006-02-01.14:48:37.000>
creator = 'jens_engel'
dependencies = []
files = []
hgrepos = []
issue_num = 1421513
keywords = []
message_count = 2.0
messages = ['27393', '27394']
nosy_count = 2.0
nosy_names = ['georg.brandl', 'jens_engel']
pr_nums = []
priority = 'normal'
resolution = 'postponed'
stage = None
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue1421513'
versions = []

Activity

  1. jensengel commented on Feb 1, 2006

    @jensengel
    jensengelmannequin
    on Feb 1, 2006
    MannequinAuthor
    More actions

    PYTHON: 2.3, 2.4
    PLATFORMS: Solaris, Linux, Cygwin, Win32

    Local sister modules seem to hide global ones (of the
    standard Python library) when import occurs in a
    submodule. This statement even holds for indirect
    imports from the standard Python library.

    FILE STRUCTURE for EXAMPLES:

    • my/
      +-- __init__.py
      +-- main.py
      +-- main2.py
      +-- symbol.py
      \-- types.py

    EXAMPLE 1: Local submodule shadows global one.
    # -- file:my.main.py
    # COMMAND-LINE: python my/main.py
    # MY INTENTION: Import standard module "types".
    import types #< FAILURE: Imports my.types

    if __name__ == "__main__":
        print types.StringTypes  #< EXCEPTION: StringTypes 
    are not known.
    # -- FILE-END

    EXAMPLE 2: Indirect import uses "my.symbol" instead.
    # -- file:my.main2.py
    # COMMAND-LINE: python my/main2.py
    # MY INTENTION: Import standard module "compiler".
    # NOTE: Module "compiler" imports module "symbol"
    import compiler #< FAILURE: Imports my.symbol instead

    if __name__ == "__main__":
        pass
    # -- FILE-END
      
    NOTE: Module import problems can be better checked 
    with "python -v".

    I have not found a work-around that let me decide if I
    want to import the global module or the local one. The
    only solution seens to be to relocate the module
    where "__main__" is used to another place where no
    such import conflict occurs.

    If my analysis is correct, the "main" module provides
    another ROOT filesystem for Python libraries that is
    normally preferred over the PYTHONHOME filesystem.
    If this is true, module names at this level must be
    UNIQUE in a GLOBAL namespace (that is only partly
    under my control) which I consider BAD.

    NOTE: In C++ if have the "::" prefix to indicate that
    I want to use the global/default namespace (=module)
    and not a sub-namespace. I am not aware of such a idom
    in Python.

  2. jensengel
    closed this as completedon Feb 1, 2006
  3. jensengel
    added
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    on Feb 1, 2006
  4. jensengel
    closed this as completedon Feb 1, 2006
  5. jensengel
    added
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    on Feb 1, 2006
  6. birkenfeld commented on Feb 17, 2006

    @birkenfeld
    birkenfeld
    on Feb 17, 2006
    Member
    More actions

    Logged In: YES
    user_id=1188172

    This is, unfortunately, correct behavior. Python 2.5 will
    hopefully fix this with new import semantics for relative
    imports.

    As a workaround, don't call your modules like global ones
    when you need those.

  7. ezio-melotti
    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-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.