8000 stubtest: increase coverage by hauntsaninja · Pull Request #11634 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

stubtest: increase coverage #11634

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 5 commits into from
Dec 1, 2021
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix
  • Loading branch information
hauntsaninja committed Nov 29, 2021
commit c93faf8ff71cedc62e2b49e47daf7d930817cd5e
37 changes: 24 additions & 13 deletions mypy/stubtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,23 +200,34 @@ def verify_mypyfile(
yield Error(object_path, "is not a module", stub, runtime)
return

# Check things in the stub that are public
# Check things in the stub
to_check = set(
m
for m, o in stub.names.items()
# TODO: change `o.module_public` to `not o.module_hidden`
if o.module_public and (not m.startswith("_") or hasattr(runtime, m))
if not o.module_hidden and (not m.startswith("_") or hasattr(runtime, m))
)
runtime_public_contents = [
m
for m in dir(runtime)
if not m.startswith("_")
# Ensure that the object's module is `runtime`, since in the absence of __all__ we don't
# have a good way to detect re-exports at runtime.
and getattr(getattr(runtime, m), "__module__", None) == runtime.__name__
]
# Check all things declared in module's __all__, falling back to runtime_public_contents
to_check.update(getattr(runtime, "__all__", runtime_public_contents))

def _belongs_to_runtime(attr: str) -> bool:
runtime_attr = getattr(runtime, attr)
runtime_attr_module = getattr(runtime_attr, "__module__", None)
if runtime_attr_module is not None:
return runtime_attr_module == runtime.__name__
return not isinstance(runtime_attr, types.ModuleType)

def _runtime_public_contents() -> List[str]:
if hasattr(runtime, "__all__"):
return getattr(runtime, "__all__")
return [
m
for m in dir(runtime)
if not m.startswith("_")
# Ensure that the object's module is `runtime`, since in the absence of __all__ we don't
# have a good way to detect re-exports at runtime.
and _belongs_to_runtime(m)
]

# Check all things declared in module's __all__, falling back to our best guess
to_check.update(_runtime_public_contents())
to_check.difference_update({"__file__", "__doc__", "__name__", "__builtins__", "__package__"})

for entry in sorted(to_check):
Expand Down
0