Import is resolving the wrong module

Open
#937 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
python
Domain
cli

Research direction

Start at invoke/loader.py#L77 and reproduce the reported project layout with tasks/common.py and a same-named site-packages module. Trace which module is selected during import, then verify that the external module is resolved instead of tasks/common.py and add coverage for the conflict if the existing test layout identifies a suitable place.

Written by the indexing model from the issue text.

Description

If you have a submodule under tasks that has the same name as a top-level module, the import will fail.

For example, I have a module named common which is located in my site-packages.
My tasks directory looks like:

/project
  /tasks
    __init__.py
    common.py
     

The issue is pretty simple,
https://github.com/pyinvoke/invoke/blob/main/invoke/loader.py#L77

import common now comes from /project/tasks instead of my site-packages.

Dominant language
Python
Stars
4.8k
Forks
412
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

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.

More from pyinvoke/invoke

All issues in pyinvoke/invoke

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.