`import p.b` when p's `__init__.py` is not in build silently produces any

Open
#4,797 1 comment 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

Research direction

Start with the test cases testInitNotInBuild1, testInitNotInBuild2, and testInitNotInBuild3, using the p/init.py, p/a.py, and p/b.py fixtures. Run the mypy -m p.a p.b command with --follow-imports=skip and trace the differing import behavior. Done means testInitNotInBuild1 reports the incompatible str argument, like the two from-import variants.

Written by the indexing model from the issue text.

Description

bug

The following test fails, producing no output:

[case testInitNotInBuild1]
# cmd: mypy -m p.a p.b
# flags: --follow-imports=skip
[file p/__init__.py]
[file p/a.py]
import p.b
p.b.f('hi')  # E: Argument 1 to "f" has incompatible type "str"; expected "int"
[file p/b.py]
def f(x: int) -> None: pass

Adding a reveal_type(p.b) reveals that its type is Any.

The following two variants of this test, using from ... import ..., both pass, however:

[case testInitNotInBuild2]
# cmd: mypy -m p.a p.b
# flags: --follow-imports=skip
[file p/__init__.py]
[file p/a.py]
from p.b import f
f('hi')  # E: Argument 1 to "f" has incompatible type "str"; expected "int"
[file p/b.py]
def f(x: int) -> None: pass

[case testInitNotInBuild3]
# cmd: mypy -m p.a p.b
# flags: --follow-imports=skip
[file p/__init__.py]
[file p/a.py]
from p import b
b.f('hi')  # E: Argument 1 to "f" has incompatible type "str"; expected "int"
[file p/b.py]
def f(x: int) -> None: pass
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.