python / python/mypy

Incorrect diagnostic on missing submodule

Open
#17,846 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

Bug Report

When untyped module exists but submodule does not, mypy reports that submodule is installed.

To Reproduce

$ pip install fabric
import fabric
from fabric.not_exists import something
$ python3 test.py
Traceback (most recent call last):
  File "/media/sf_d/WWPass/git/spm/test.py", line 2, in <module>
    from fabric.not_exists import something
ModuleNotFoundError: No module named 'fabric.not_exists'

$ mypy test.py
test.py:1:1: error: Skipping analyzing "fabric": module is installed, but missing library stubs or py.typed marker  [import-untyped]
    import fabric
    ^
test.py:2:1: error: Skipping analyzing "fabric.not_exists": module is installed, but missing library stubs or py.typed marker  [import-untyped]
    from fabric.not_exists import something
    ^
test.py:2:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
Found 2 errors in 1 file (checked 1 source file)

Expected Behavior
Error in line 2 should be saying that fabric.not_exists does not exist.

Actual Behavior
Error in line 2 says that fabric.not_exists is installed, which it not true and misleading.

Your Environment

$ mypy --version
mypy 1.11.2 (compiled: yes)

$ python3 --version
Python 3.12.3

$ pip list | grep fabric
fabric 3.2.2

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 report with the shown test.py, an installed untyped fabric package, and the import of fabric.not_exists. Start by tracing mypy's import resolution and missing-stub diagnostic for nested modules; done means the existing package still reports its current warning while the missing submodule gets a clear does-not-exist error.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.