python / python/cpython

Non-package module loaded from ModInfo object retains __path__ from previously loaded package.

Open
#97,694 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

type-bug
Dominant language
Python
Stars
77.2k
Forks
36k
PR merge metrics
PR metrics pending

Description

Bug report

Assume you have two separate modules with the same name. One is a package, one is not.

Use pkgutil.itermodules to get a ModuleInfo object for the package, then load the it using find_module and load_module. This object has a __path__ object with the location of package, as expected.

Next, do the same for the non-package module. The resulting module object should have no __path__ attribute, but instead it has one with the location of the package opened previously.

This can be replicated with a structure such as \module\submodule\submodule.py, using \module and \module\submodule as the arguments for the two calls to pkgutil.itermodules.

Your environment

  • CPython versions tested on: 3.10.7, 3.11.0rc2
  • Operating system and architecture: Windows 10

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the behavior with the two module layouts described in the issue, using pkgutil.itermodules followed by find_module and load_module. Compare the package and non-package module objects; done means the non-package module no longer retains a path from the previously loaded package.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.