From eb0575eaa8720b2cdac62c7deb4c54c53035ea3b Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Wed, 23 Oct 2024 22:06:39 +0200 Subject: [PATCH] [stubtest] Verify __all__ exists in stub (#18005) Previously it wasn't an error if runtime included an `__all__` declaration, but the stubs did not. This PR changes this to reflect the consensus that it would be a good idea to ensure consistency in this case. Fixes #13300 --- mypy/stubtest.py | 2 ++ mypy/test/teststubtest.py | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/mypy/stubtest.py b/mypy/stubtest.py index 756f90dccf2e..0de5411b01de 100644 --- a/mypy/stubtest.py +++ b/mypy/stubtest.py @@ -348,6 +348,8 @@ def verify_mypyfile( # Only verify the contents of the stub's __all__ # if the stub actually defines __all__ yield from _verify_exported_names(object_path, stub, runtime_all_as_set) + else: + yield Error(object_path + ["__all__"], "is not present in stub", MISSING, runtime) else: runtime_all_as_set = None diff --git a/mypy/test/teststubtest.py b/mypy/test/teststubtest.py index 70687b499651..4cab62875647 100644 --- a/mypy/test/teststubtest.py +++ b/mypy/test/teststubtest.py @@ -1403,7 +1403,7 @@ def test_all_at_runtime_not_stub(self) -> Iterator[Case]: runtime=""" __all__ = [] Z = 5""", - error=None, + error="__all__", ) @collect_cases @@ -1443,7 +1443,7 @@ def h(x: str): ... runtime="", error="h", ) - yield Case(stub="", runtime="__all__ = []", error=None) # dummy case + yield Case(stub="", runtime="__all__ = []", error="__all__") # dummy case yield Case(stub="", runtime="__all__ += ['y']\ny = 5", error="y") yield Case(stub="", runtime="__all__ += ['g']\ndef g(): pass", error="g") # Here we should only check that runtime has B, since the stub explicitly re-exports it