Skip to content

Commit eb0575e

Browse files
authored
[stubtest] Verify __all__ exists in stub (python#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 python#13300
1 parent 9e68959 commit eb0575e

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

mypy/stubtest.py

+2
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,8 @@ def verify_mypyfile(
348348
# Only verify the contents of the stub's __all__
349349
# if the stub actually defines __all__
350350
yield from _verify_exported_names(object_path, stub, runtime_all_as_set)
351+
else:
352+
yield Error(object_path + ["__all__"], "is not present in stub", MISSING, runtime)
351353
else:
352354
runtime_all_as_set = None
353355

mypy/test/teststubtest.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1403,7 +1403,7 @@ def test_all_at_runtime_not_stub(self) -> Iterator[Case]:
14031403
runtime="""
14041404
__all__ = []
14051405
Z = 5""",
1406-
error=None,
1406+
error="__all__",
14071407
)
14081408

14091409
@collect_cases
@@ -1443,7 +1443,7 @@ def h(x: str): ...
14431443
runtime="",
14441444
error="h",
14451445
)
1446-
yield Case(stub="", runtime="__all__ = []", error=None) # dummy case
1446+
yield Case(stub="", runtime="__all__ = []", error="__all__") # dummy case
14471447
yield Case(stub="", runtime="__all__ += ['y']\ny = 5", error="y")
14481448
yield Case(stub="", runtime="__all__ += ['g']\ndef g(): pass", error="g")
14491449
# Here we should only check that runtime has B, since the stub explicitly re-exports it

0 commit comments

Comments
 (0)