Skip to content

Commit f08c57e

Browse files
stubtest: do not treat py files as source for mypy definitions (#12889)
Authored by @KotlinIsland Co-authored-by: KotlinIsland <kotlinisland@users.noreply.github.com>
1 parent e661890 commit f08c57e

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

mypy/stubtest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1301,7 +1301,8 @@ def build_stubs(modules: List[str], options: Options, find_submodules: bool = Fa
13011301

13021302
def get_stub(module: str) -> Optional[nodes.MypyFile]:
13031303
"""Returns a stub object for the given module, if we've built one."""
1304-
return _all_stubs.get(module)
1304+
stub = _all_stubs.get(module)
1305+
return stub if stub and stub.is_stub else None
13051306

13061307

13071308
def get_typeshed_stdlib_modules(

mypy/test/teststubtest.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,6 +1201,18 @@ def test_missing_stubs(self) -> None:
12011201
"Found 1 error (checked 1 module)\n"
12021202
)
12031203

1204+
def test_missing_only_stubs(self) -> None:
1205+
with use_tmp_dir(TEST_MODULE_NAME):
1206+
with open(f"{TEST_MODULE_NAME}.py", "w") as f:
1207+
f.write("a = 1")
1208+
output = io.StringIO()
1209+
with contextlib.redirect_stdout(output):
1210+
test_stubs(parse_options([TEST_MODULE_NAME]))
1211+
assert (
1212+
f"error: {TEST_MODULE_NAME} failed to find stubs"
1213+
in remove_color_code(output.getvalue())
1214+
)
1215+
12041216
def test_get_typeshed_stdlib_modules(self) -> None:
12051217
stdlib = mypy.stubtest.get_typeshed_stdlib_modules(None, (3, 6))
12061218
assert "builtins" in stdlib

0 commit comments

Comments
 (0)