From 6a200947fdd36f77a5e9ecd2ec2283834a2f3989 Mon Sep 17 00:00:00 2001 From: hauntsaninja <> Date: Fri, 27 May 2022 20:34:10 -0700 Subject: [PATCH] stubtest: do not treat py files as source for mypy definitions --- mypy/stubtest.py | 3 ++- mypy/test/teststubtest.py | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/mypy/stubtest.py b/mypy/stubtest.py index c1bdcb3437a4..2c31b83ba0af 100644 --- a/mypy/stubtest.py +++ b/mypy/stubtest.py @@ -1274,7 +1274,8 @@ def build_stubs(modules: List[str], options: Options, find_submodules: bool = Fa def get_stub(module: str) -> Optional[nodes.MypyFile]: """Returns a stub object for the given module, if we've built one.""" - return _all_stubs.get(module) + stub = _all_stubs.get(module) + return stub if stub and stub.is_stub else None def get_typeshed_stdlib_modules( diff --git a/mypy/test/teststubtest.py b/mypy/test/teststubtest.py index 50b3f90c8fad..726ef5bb1caf 100644 --- a/mypy/test/teststubtest.py +++ b/mypy/test/teststubtest.py @@ -1161,6 +1161,18 @@ def test_missing_stubs(self) -> None: test_stubs(parse_options(["not_a_module"])) assert "error: not_a_module failed to find stubs" in remove_color_code(output.getvalue()) + def test_missing_only_stubs(self) -> None: + with use_tmp_dir(TEST_MODULE_NAME): + with open(f"{TEST_MODULE_NAME}.py", "w") as f: + f.write("a = 1") + output = io.StringIO() + with contextlib.redirect_stdout(output): + test_stubs(parse_options([TEST_MODULE_NAME])) + assert ( + f"error: {TEST_MODULE_NAME} failed to find stubs" + in remove_color_code(output.getvalue()) + ) + def test_get_typeshed_stdlib_modules(self) -> None: stdlib = mypy.stubtest.get_typeshed_stdlib_modules(None, (3, 6)) assert "builtins" in stdlib