diff --git a/mypy/stubtest.py b/mypy/stubtest.py index 7915e14f1551..f0fb16900bde 100644 --- a/mypy/stubtest.py +++ b/mypy/stubtest.py @@ -202,6 +202,13 @@ def verify_mypyfile( if isinstance(runtime, Missing): yield Error(object_path, "is not present at runtime", stub, runtime) return + + # Workaround for pyOpenSSL that has its module objects wrapped. + # See https://github.com/python/typeshed/pull/5657 for details. + if f"{type(runtime).__module__}.{type(runtime).__qualname__}" \ + == "cryptography.utils._ModuleWithDeprecations": + runtime = runtime._module # type: ignore[attr-defined] + if not isinstance(runtime, types.ModuleType): yield Error(object_path, "is not a module", stub, runtime) return @@ -652,6 +659,12 @@ def verify_funcitem( yield Error(object_path, "is not present at runtime", stub, runtime) return + # Workaround for pyOpenSSL that has some of its function objects wrapped. + # See https://github.com/python/typeshed/pull/5657 for details. + if f"{type(runtime).__module__}.{type(runtime).__qualname__}" \ + == "cryptography.utils._DeprecatedValue": + runtime = runtime.value + if ( not isinstance(runtime, (types.FunctionType, types.BuiltinFunctionType)) and not isinstance(runtime, (types.MethodType, types.BuiltinMethodType))