Skip to content

Workaround to stubtest to handle pyOpenSSL correctly #10663

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

Closed
wants to merge 7 commits into from
Closed
Changes from all commits
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
13 changes: 13 additions & 0 deletions mypy/stubtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down