Skip to content

stubtest: do not treat py files as source for mypy definitions #12889

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion mypy/stubtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
12 changes: 12 additions & 0 deletions mypy/test/teststubtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down