Confusing message for indirect import from a stub

Open
#4,091 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

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

Research direction

Download testcase.zip and run mypy --config-file=mypy.ini -p testcase to reproduce the reported errors. Start with teststubs/a/stubA.pyi, testcase/init.py, b.init.pyi, and b.stubB, then trace why the indirect import is not recognized. Done means the supplied case no longer reports either missing TestClass error.

Written by the indexing model from the issue text.

Description

priority-1-normal topic-error-reporting topic-usability

Indirect imports in stubs don't seem to work. I tested the following case against mypy 0.520, where everything worked (no error detected), mypy 0.530 (where the error occurred) and the current git version, which also had the same error as mypy 0.530.

I attached a zip file with the test case:
testcase.zip

The mypy call line is just mypy --config-file=mypy.ini -p testcase.

The error I get is the following:

teststubs/a/stubA.pyi:1: error: Module 'b' has no attribute 'TestClass'
testcase/__init__.py:1: error: Module 'a.stubA' has no attribute 'TestClass'

The main problem is the first line. Module 'b' imports 'TestClass' from b.stubB in b.__init__.pyi, but mypy for some reason does not know that.

Dominant language
Python
Stars
20.6k
Forks
3.3k
Avg merge
1d 18h
Merged PRs (30d)
54

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.

More from python/mypy

All issues in python/mypy

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.