diff --git a/mypy/stubtest.py b/mypy/stubtest.py index e80ea4eac71f..3ff40f4c0ce8 100644 --- a/mypy/stubtest.py +++ b/mypy/stubtest.py @@ -355,7 +355,7 @@ def verify_mypyfile( def _belongs_to_runtime(r: types.ModuleType, attr: str) -> bool: """Heuristics to determine whether a name originates from another module.""" obj = getattr(r, attr) - if isinstance(obj, types.ModuleType): + if isinstance(obj, types.ModuleType) and not (r is sys and attr == "monitoring"): return False if callable(obj): # It's highly likely to be a class or a function if it's callable, @@ -390,7 +390,9 @@ def _belongs_to_runtime(r: types.ModuleType, attr: str) -> bool: for entry in sorted(to_check): stub_entry = stub.names[entry].node if entry in stub.names else MISSING - if isinstance(stub_entry, nodes.MypyFile): + if isinstance(stub_entry, nodes.MypyFile) and not ( + runtime is sys and entry == "monitoring" + ): # Don't recursively check exported modules, since that leads to infinite recursion continue assert stub_entry is not None